-2

Is sure to cast ? super T to T?

Example:

public void method(? super Date param)
{
    Date d = (Date)param;
}

I'm not able to do Date d = param. Why?

Jordi
  • 18,082
  • 29
  • 125
  • 263

1 Answers1

1

You need to follow a tutorial on generics ;)

Here's what it should look like:

public <T extends Date> void method(T date){
    Date d = date;
}

You specify the generic type before the parameter input. I suggest taking the time to read this: https://docs.oracle.com/javase/tutorial/java/generics/

Roel Strolenberg
  • 2,892
  • 1
  • 13
  • 29