-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
  • 20,868
  • 39
  • 149
  • 333

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,922
  • 1
  • 15
  • 29