That would not be safe, since you can't be sure of the underlying Type. If you just need to access the methods defined by the Set
interface, then you should use:
Set<String> set = wordGame.giveUp();
If this happens to be a LinkedSet
your code would "work", but if not you will get a ClassCastException
. If you need it to be a LinkedSet
specifically for any reason, then the giveUp()
method should return a LinkedSet
explicitly.