Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is true that generics aren't generally known at runtime in Java, because they are implemented with Type Erasure.</p> <h2>Reflecting Generics?</h2> <p>However, you can stil extract some valuable information about the <strong>declared types</strong> (NOT the runtime objects' types), as presented in Ian Roberston's article <em><a href="http://www.artima.com/weblogs/viewpost.jsp?thread=208860" rel="nofollow noreferrer">Reflecting Generics</a></em> and Prenkov's article <em><a href="http://tutorials.jenkov.com/java-reflection/generics.html" rel="nofollow noreferrer">Java Reflection: Generics</a></em>.</p> <h2>Background on Generics and Type Erasure</h2> <p>Generics where introduced while conserving backwards compatibility at the source qnd binary level, hence some of their limitation, like:</p> <ul> <li>the impossibility to have a short-hand form without at least some indicator for generics support (here, the so-called <strong>diamond operator</strong> <code>&lt;&gt;</code>),</li> <li>the impossibility to inspect generic-types at runtime, because they had to be implemented with <strong><a href="http://docs.oracle.com/javase/tutorial/java/generics/erasure.html" rel="nofollow noreferrer">Type Erasure</a></strong>.</li> </ul> <h3>Further Reading</h3> <ul> <li>From <a href="http://docs.oracle.com/javase/tutorial/" rel="nofollow noreferrer">The Java Tutorial</a>: <ul> <li>section on <a href="http://docs.oracle.com/javase/tutorial/java/generics/gentypes.html" rel="nofollow noreferrer">Generic Types</a></li> <li>section on <a href="http://docs.oracle.com/javase/tutorial/java/generics/gentypeinference.html#type-inference-instantiation" rel="nofollow noreferrer">Type Inference and Instantiation of Generic Classes</a></li> </ul></li> <li>From the Java <a href="http://docs.oracle.com/javase/specs/" rel="nofollow noreferrer">Language Specifications</a> (JLS): <ul> <li><a href="http://docs.oracle.com/javase/specs/jls/se5.0/html/j3TOC.html" rel="nofollow noreferrer">Java SE 5's JLS</a> section on <a href="http://docs.oracle.com/javase/specs/jls/se5.0/html/typesValues.html" rel="nofollow noreferrer">Types, Values and Variables</a></li> <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/index.html" rel="nofollow noreferrer">Java SE 7's JLS</a> section on <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html" rel="nofollow noreferrer">Types, Values and Variables</a></li> </ul></li> <li>From good StackOverflow questions: <ul> <li><a href="https://stackoverflow.com/questions/1206028/java-raw-type-and-generics-interaction">Java Raw Type and generics interaction</a></li> </ul></li> <li>Others: <ul> <li>IBM Developer Series: <a href="http://www.ibm.com/developerworks/java/library/j-jtp01255/index.html" rel="nofollow noreferrer">Java Theory and Practice: Generics Gotchas</a> (especially the sections <strong>The Road Not Taken</strong>, <strong>Generifying Existing Classes</strong> and <strong>Implications of Erasure</strong>).</li> </ul></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload