Well, aren't "Types" just classes? Even primitives TYPES are classes, too.
When you use a generic, doesn't it just send the reference of the class to the variable?
classTest<T>{// T is our generic.publicTest(Tvalue/* T is a reference to the class. */){/* code... */}}Test<String>test=newTest<>();// T in this instance is Test is a reference to String.
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.
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.
Well, aren't "Types" just classes? Even primitives TYPES are classes, too.
When you use a generic, doesn't it just send the reference of the class to the variable?
?
Is this true, or no?
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.
What if I use
String.class
?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.
Okay.
Thanks.
Cheers.