I am reading the chapter on Generics in Effective Java.
Help me understand difference between Set
, Set<?>
and Set<Object>
?
The following paragraph is taken from the book.
As a quick review, Set<Object>
is a parameterized type representing a
set that can contain objects of any type, Set<?>
is a wildcard type
representing a set that can contain only objects of some unknown
type, and Set
is a raw type, which opts out of the generic type
system.
What is meant by "some unknown type"? Are all unknown types of type Object
? In that case what is the specific difference between Set<?>
and Set<Object>
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…