I understand this occurs with Java 7 when using varargs with a generic type;
But my question is..
What exactly does Eclipse mean when it says “its use could potentially pollute the heap?”
And
How does the new @SafeVarargs annotation prevent this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Heap pollution is a technical term. It refers to references which have a type that is not a supertype of the object they point to.
This can lead to "unexplainable"
ClassCastExceptions.@SafeVarargsdoes not prevent this at all. However, there are methods which provably will not pollute the heap, the compiler just can’t prove it. Previously, callers of such APIs would get annoying warnings that were completely pointless but had to be suppressed at every call site. Now the API author can suppress it once at the declaration site.However, if the method actually is not safe, users will no longer be warned.