I am reading through AngelikaLangerDoc. I am reading it after a gap of almost three days.
In my earlier lesson, i learnt that, arrays of unbounded wild card
are allowed to be created.
I also studied unbounded wild-card parameterized types are called Reifiable types
. When i searched
the definition of reifiable type, it states that, a type whose type information is known at run-time
is called reifiable type
. Picking a code snippet from the article.
Pair<?,?>[] iniPair = new Pair<?,?>[10];
I have the following confusion in mind.
I know it's a basic question. I am just trying to get back the refresher to get back on track of Generics. Can anyone elaborate on this issue?
From that website:
the reifiable types in Java are only those types for which reification does not make a difference, that is, the types that do not need any runtime representation of type arguments
There is no type information in the wildcard parameters, therefore nothing is lost by erasure.
Since Java compiler replace all unbounded type parameters to Object
.
According to Type Erasure
To implement generics, the Java compiler applies type erasure to:
1.Replace all type parameters in generic types with their bounds or Object if the type parameters are unbounded. The produced bytecode, therefore, contains only ordinary classes, interfaces, and methods.
2.Insert type casts if necessary to preserve type safety.
3.Generate bridge methods to preserve polymorphism in extended generic types.
The term Reifiable according to Javadoc
A reifiable type is a type whose type information is fully available at runtime. This includes primitives, non-generic types, raw types, and invocations of unbound wildcards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With