Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why we call unbounded wild-card parameterized type as reifiable?

Tags:

java

generics

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.

  1. Why we say unbounded wild-card parameterized type is called reifiable?
  2. In example above, how the type information is known?

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?

like image 436
benz Avatar asked Aug 23 '13 20:08

benz


2 Answers

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.

like image 197
Oliver Charlesworth Avatar answered Sep 27 '22 21:09

Oliver Charlesworth


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.

like image 37
Prabhaker A Avatar answered Sep 27 '22 21:09

Prabhaker A