The warning is completely correct; your code makes no sense.
By writing <T> T[] toArray()
, you've made a function that can be called with any type parameter and will return an array of that type.
Always returning an array of ABC
s violates what you claimed it will do.
In short, that function should not be generic.
None of this is applicable to your case, because the base Set<E>
interface requires this.
I have no idea why Set<E>
is declared that way, but there is nothing you can do about the warning.