Heap Pollution
   HOME

TheInfoList



OR:

In the
Java programming Java is a high-level, general-purpose, memory-safe, object-oriented programming language. It is intended to let programmers ''write once, run anywhere'' ( WORA), meaning that compiled Java code can run on all platforms that support Java w ...
language, heap pollution is a situation that arises when a variable of a parameterized type refers to an object that is not of that parameterized type. This situation is normally detected during compilation and indicated with an unchecked warning. Later, during runtime heap pollution will often cause a ClassCast Exception. Heap pollution in Java can occur when type arguments and variables are not reified at run-time. As a result, different parameterized types are implemented by the same class or
interface Interface or interfacing may refer to: Academic journals * ''Interface'' (journal), by the Electrochemical Society * '' Interface, Journal of Applied Linguistics'', now merged with ''ITL International Journal of Applied Linguistics'' * '' Inter ...
at run time. All invocations of a given generic type declaration share a single run-time implementation. This results in the possibility of heap pollution. Under certain conditions, a variable of a parameterized type may refer to an object that is not of that parameterized type. The variable will always refer to an object that is an instance of a class that implements the parameterized type. Heap Pollution in a non- varargs context public class HeapPollutionDemo


Further reading

* * * *


References

Java platform {{prog-lang-stub