See also

Asking for feedback: is it true that the cast in newSet is considered "safe"? I don't think it actually is, because one can create SpecializedStringSet implements Set<String>, and Set<Integer> nums = newSet(SpecializedStringSet.class); could throw ClassCastException at run-time on add, right? I'll edit this into the answer based on comments.
–
polygenelubricantsJul 12 '10 at 11:17

you are correct, it is not safe, that is why you have to suppress warnings.
–
YishaiJul 12 '10 at 19:35

@Yishai: it's unchecked, which is why you have to suppress the warning. I'm wondering if it's also unsafe. Just because it's unchecked doesn't mean it's unsafe. If it's unsafe, then suppressing the warning is foolish. If it's provably safe, then suppress away and you're fine.
–
polygenelubricantsJul 12 '10 at 19:37

you demonstrated that it is unsafe in your comment.
–
YishaiJul 13 '10 at 2:19

The problem here is that EasyMock.createMock() is going to return an object of type GenericInterface and not GenericInterface<String>. You could use the @SupressWarnings annotation to ignore the warning, or you could try and explicit cast to GenericInterface<String> (I think this just gives a different warning though.)