Whenever you have varargs that are generic (like a generic list), you have the possibility of polluting the heap. For example:
public void doSomethingWithStrings(List<String>... strings) { Object[] objectArray = strings;
In your example, do you have Class<? extends Event> eventTypes... Class<? extends Event> eventTypes... , which falls prey to the same problem:
public static void register(EventListener listener, Class<? extends Event>... eventTypes) { Object[] objectArray = eventTypes; objectArray[0] = String.class;
Java just warns you that there is a potential heap protection solution. In Java 7, warnings are generated when a method is declared, and in previous versions this was only on call sites.
If you are sure that heap contamination cannot occur, you can suppress the warning using the @SafeVarargs annotation.
Vivin paliath
source share