DEV Community

Discussion on: Is there vararg-like generics in Java?

 
alainvanhout profile image
Alain Van Hout

I'm talking about the actual user input, not the developer.

With regard to your example, in Java that variable will be an object of type Test, which at compile time will have verified to use the type String in all cases where T is used in the general definition of the class. So no, no reference of the class is sent to the variable.

Thread Thread
 
calinbaenen profile image
Calin Baenen

What if I use String.class?

Thread Thread
 
alainvanhout profile image
Alain Van Hout

String.class is a object representing the String type. But that's not what is needed here.

Think of it like this: if you have a generic box, a banana box and an apple box, then you can't transform a generic box into a banana box by throwing a banana at it. The banana needs to conceptually be in the picture when the box its design is created.

Thread Thread
 
calinbaenen profile image
Calin Baenen • Edited

Okay.

Thanks.
Cheers.