Generics

Discussion in 'Java' started by Smallfernandes, Mar 17, 2005.

  1. As we know, J2SE 1.5 supports generic programing, but anyone knows if
    there's some performance implications about using generics in java ??
    (besides code reutilization :) )
    Smallfernandes, Mar 17, 2005
    #1
    1. Advertising

  2. Smallfernandes wrote:

    > As we know, J2SE 1.5 supports generic programing, but anyone knows if
    > there's some performance implications about using generics in java ??
    > (besides code reutilization :) )
    >


    Use of Java generics has no runtime performance impact whatsoever
    relative to the equivalent non-generic code. The type information
    associated with generics is used for compile-time checks, but it has no
    runtime manifestation.

    --
    John Bollinger
    John C. Bollinger, Mar 17, 2005
    #2
    1. Advertising

  3. "John C. Bollinger" <> wrote in message news:<d1d0pv$4r4$>...
    > Smallfernandes wrote:
    >
    > > As we know, J2SE 1.5 supports generic programing, but anyone knows if
    > > there's some performance implications about using generics in java ??
    > > (besides code reutilization :) )
    > >

    >
    > Use of Java generics has no runtime performance impact whatsoever
    > relative to the equivalent non-generic code. The type information
    > associated with generics is used for compile-time checks, but it has no
    > runtime manifestation.


    Correct, but one should know that since the JVM has no knowledge of
    generic types the compiler insert casts in the code whenever a generic
    type is used. So, for example:

    class PointList {
    ...

    public Point get(int index) {
    ...
    }
    }

    is probably a bit more efficient than:

    class List<T> {
    ...

    public T get(int index) {
    ...
    }
    }

    But that shouldn't stop you from using generic types. And often the
    cast can be optimized away by HotSpot.

    /Jesper Nordenberg
    Jesper Nordenberg, Mar 18, 2005
    #3
    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. Willem Oosthuizen
    Replies:
    1
    Views:
    2,781
    Jonathan Bromley
    Jul 9, 2003
  2. Acciduzzu

    Integers only as generics?

    Acciduzzu, Sep 22, 2003, in forum: VHDL
    Replies:
    4
    Views:
    714
    Allan Herriman
    Sep 23, 2003
  3. valentin tihomirov

    generics in TB

    valentin tihomirov, Dec 17, 2003, in forum: VHDL
    Replies:
    4
    Views:
    582
    valentin tihomirov
    Dec 18, 2003
  4. Juergen Berchtel
    Replies:
    1
    Views:
    5,987
    John C. Bollinger
    May 20, 2005
  5. Soul
    Replies:
    0
    Views:
    514
Loading...

Share This Page