0

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?

1
  • 3
    Code examples of the usages you're asking to have compared would be very helpful. Commented Jul 19, 2011 at 22:00

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.