Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is main advantage of generics in 1.5

 
vinod sai
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Please tell me generics advantage in java 1.5.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It comes down to type safety.

Prior to Java 5 and generics, you could place any type of Object in a List, Map, etc.

This resulted in a lot of casting and error prone code.

Generics lets you tell the Map that only objects of type MyFancyObject go into the Map, nothing else, end of story.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Beginning Java.

And read this.
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generics Tutorial
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic