why Generic types only for Object?
What I mean is
interface A <T> {
}
class AImpl implements A < Integer > {开发者_开发百科 // why not A< int >
}
I have read this article and googled it but still I have no idea why it is only for Object and not for primitive data types(int, void)?
It's not just wildcards - Java generics simply don't support primitive types as type arguments at all.
See the Java Generics FAQ for more information about Java Generics in general, and this question in particular.
Generics don't work for int, float, boolean, etc. because primitive types do not have all of the associated metadata and structures that Object based types have. In Java primitive types are just that, primitive. All of that associated metadata enables things like generics, reflection, subclassing, etc.
精彩评论