Reputation: 39
what is the difference between these two in java? I always get confused when using the <> syntax. when is better to create a generic class than to use generic methods from collection classes?
Upvotes: 0
Views: 136
Reputation: 19823
Does your class benefit from class type parametrization? Then make it generic class and remember that generics class get replaced with concrete class type at compile time.
Upvotes: 0
Reputation: 28451
Collection classes use generics (a kind of parametric polymorphism) since Java 5, so users of the library don't have to cast the elements of the collection themselves anymore.
Therefore, collection classes are a nice example how generics can be used to make developers lives easier, apart from that generics and collection are completely different topics.
Upvotes: 3