File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Java 5 Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Java 5 Generics" Watch "Java 5 Generics" New topic
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java 5 Generics
 
Similar Threads
Generics
Generics
Generics
generics
Generics