Using generics in Java
•
Java
I just started using Java, so this may be a stupid question for most people,
Set<T> mySet;
Eclipse gives an error: the local variable myset may not have been initialized Than I tried to initialize it:
Set<T> mySet = new Set<T>();
But eclipse gives an error: "cannot instantiate type set."
What did I do wrong here?
Solution
Setting < T > is an interface and cannot be instantiated You can use HashSet < T >:
Set<T> set = new HashSet<T>();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码