| Author |
Java 5 Generics
|
Srivatsan santhanam
Greenhorn
Joined: Jan 04, 2006
Posts: 23
|
|
Hi, I saw that in Java 5 we can make use of Generics to have declarations like Set<String> s = new HashSet<String>(); but, Can i also use UserDefined Objects also ? like Set<EmployeeName> s = new HastSet<EmployeeName>(); Does this Generics information also made part of the Genearated .class file (byteCode) ? or is it only meant for Java Compiler and is lost after compilation? -Srivats
|
Java Objects passed by Reference ?? -> you are a failure !!
|
 |
Joni Salonen
Ranch Hand
Joined: Jan 07, 2006
Posts: 53
|
|
Yes, you can use user defined objects, as long as they fullfill the requirements of the container poses; e.g. HashSet requires you to implement the equals and hashCode methods or otherwise it won't work quite the way you might think. The type information is lost when you compile. This is called "type erasure." See also http://java.sun.com/docs/books/tutorial/java/javaOO/generics.html http://java.sun.com/developer/technicalArticles/J2SE/generics/index.html http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf
|
 |
 |
|
|
subject: Java 5 Generics
|
|
|