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