Java Generics, Type Erasure and Frameworks

Discussion in 'Java' started by Sebastian Millies, Oct 7, 2004.

  1. I have started looking at Java Generics recently. At first, what
    I struck me as valuable was that type parameters allow one to express
    constraints that cannot (or not easily) be expressed using simple
    polymorphism.

    (An example would be a generic sort method that only accepted
    a collection if its members were comparable with themselves,
    cf. http://www.mindview.net/WebLog/wiki-0050)

    However, when I learned about the type erasure implementation
    of generics, it seemed to me that the added expressiveness was of no
    use to people designing frameworks and libraries. After all, there is no
    generic run-time type information in the jar-file you'll eventually
    distribute. So, for example, you could not create a library containing
    a sort method with the above restriction - not even if you required
    clients to use the Tiger jre.

    I then read about NextGen, and the possibility of including run-time generic
    types in Java (e.g. http://www.cs.rice.edu/~eallen/papers/nextgen-final.pdf)
    Is anything like that planned by Sun for a future Java release? If not,
    there
    seems to be little gain in using Java generics for framework development.

    -- Sebastian
     
    Sebastian Millies, Oct 7, 2004
    #1
    1. Advertising

  2. Sebastian Millies

    Chris Uppal Guest

    Sebastian Millies wrote:

    > However, when I learned about the type erasure implementation
    > of generics, it seemed to me that the added expressiveness was of no
    > use to people designing frameworks and libraries. After all, there is no
    > generic run-time type information in the jar-file you'll eventually
    > distribute.


    The type information is included in the jar files. It's just that it isn't
    used by the JVM itself, only by any 1.5-style compiler that is compiling
    against those jar files.

    There are a bunch of new "attributes" added to classfiles generated by the new
    compiler, some of which provide type information for generics. The compiler
    knows how to read and use that data when if is compiling code that uses the
    classes.

    (After all, uses of the newly generic standard library are type checked, so it
    clearly possible ;-)

    -- chris
     
    Chris Uppal, Oct 7, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. z-man
    Replies:
    8
    Views:
    373
    Thomas Weidenfeller
    Oct 9, 2006
  2. Martin Lorentzson

    Generics and type erasure

    Martin Lorentzson, Nov 5, 2006, in forum: Java
    Replies:
    2
    Views:
    422
    Martin Lorentzson
    Nov 6, 2006
  3. William
    Replies:
    5
    Views:
    1,025
  4. William
    Replies:
    3
    Views:
    654
    Andreas Leitgeb
    Mar 4, 2011
  5. Marcin Pietraszek

    Java generics and type erasure

    Marcin Pietraszek, May 23, 2011, in forum: Java
    Replies:
    29
    Views:
    1,066
Loading...

Share This Page