Answer the question
In order to leave comments, you need to log in
Why can't you use primitive types in generic classes/methods?
Hello.
We have this code:
private static <T> T testAutoboxing(T obj)
{
return obj;
}
public static void main(String[] argv)
{
System.out.println(Learn.<int>testAutoboxing(5));
}
Answer the question
In order to leave comments, you need to log in
The book only confronts the fact that only reference types can be specified. If you want primitive, then you need to resort to encapsulation.
During type erasure, int will become Object,
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question