Content deleted Content added
added reference to a mnemonics. |
→Covariance for generic types: fixed link |
||
Line 3:
== Covariance for generic types ==
Unlike arrays (which are [[Covariance and contravariance (computer science)#Covariant arrays in Java and C#|covariant]] in Java), different instantiations of a generic type are not compatible to each other, not even explicitly: With the declaration <code>Generic<Supertype> superGeneric; Generic<Subtype> subGeneric;</code> the compiler would report a conversion error for both castings <code>(Generic<Subtype>)superGeneric</code> and <code>(Generic<Supertype>)subGeneric</code>.
This incompatibility may be softened by the wildcard if <code>?</code> is used as actual type parameter: <code>Generic<?></code> is the abstract supertype for all instantiations of the generic type. It means, no objects of this type may be created, only variables. The usage of such a variable is to refer to instantiations of <code>Generic</code> with any actual type parameter.
|