heap-pollution

What is an apparently correct example of Java code causing heap pollution?

梦想的初衷 提交于 2019-12-21 07:23:12
问题 I'm trying to decide what to do every time I get a Java heap pollution warning when using parameterized varargs such as in public static <T> LinkedList<T> list(T... elements) { ... } It seems to me that if I am confident not to be using some weird casts in my methods, I should just use @SafeVarargs and move on. But is this correct, or do I need to be more careful? Is there apparently correct code that is actually not safe when using parameterized varargs? Reading about the subject, I notice

Java 1.7 varargs function reported as unchecked warning

喜夏-厌秋 提交于 2019-12-01 15:03:33
We use some varargs functions and as we move to java 1.7 we are getting a strange unchecked warning. Function add in interface ICache public interface ICache<O> { void add(Object source, O... objects); } in an interface reports the error. ICache.java:18: warning: [unchecked] Possible heap pollution from parameterized vararg type O void add(Object source, O... objects); where O is a type-variable: O extends Object declared in interface ICache 1 warning O extends Object, as its generic cache class. I read the xlint warnings and we do compile with unchecked on, but http://docs.oracle.com/javase/7

Java 1.7 varargs function reported as unchecked warning

十年热恋 提交于 2019-12-01 13:54:12
问题 We use some varargs functions and as we move to java 1.7 we are getting a strange unchecked warning. Function add in interface ICache public interface ICache<O> { void add(Object source, O... objects); } in an interface reports the error. ICache.java:18: warning: [unchecked] Possible heap pollution from parameterized vararg type O void add(Object source, O... objects); where O is a type-variable: O extends Object declared in interface ICache 1 warning O extends Object, as its generic cache