Java - Difference between Set and Set<?>

less than 1 minute read

What is difference between Set and Set<?>

Main benefit of using wildcard Set<?> is that it can guarantee the safety of collection. It will preserve invariant of wildcard collection but raw type collection will allow to add different types in collection. However Set<?> also allows to add null value.

Set<?> is preventing from corrupting collection’s type invariant.

Categories:

Updated: