Since the immutable implementation of Set.of(E e)
has been introduced in Java 9
, do we still need to use Collections.singleton(E e)
? What would be the use case for the latter one?
It doesn't seem to be obvious from looking at the source code of both implementations. I don't see any significant difference except that Set12
implementation explicitly denies deserialisation.
I would personally go for Set.of(...)
for the all new code at least because of the stylish point of view (a shorter code, less imports). But may be I am missing some crucial point?