Generics

S

Smallfernandes

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 :) )
 
J

John C. Bollinger

Smallfernandes said:
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.
 
J

Jesper Nordenberg

John C. Bollinger said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

generics puzzle 57
Generics Amanuensis? 2
A problem regarding generics 13
Web Site 1
Generics annoyance 18
subclassing and generics 19
Java generics and type erasure 29
Generics 24

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top