63

A "Heap Pollution" as in Non-Reifiable Types (The Java™ Tutorials > Learning the Java Language > Generics (Updated))

Why is it called that way?

  • 3
    A good reason for not having any warnings in your project. – user1249 Jul 8 '12 at 8:00
  • @ThorbjørnRavnAndersen Good one. But still - there should be a reason / mnemonic device behind that name. It is funny but even google does not seem to know why. – user18404 Jul 8 '12 at 8:07
71

Heap pollution simply implies that you have "bad stuff" in your heap. It is an analogy to (for example) water pollution which is where you have "bad stuff" in the water.

Specifically, the bad stuff here is objects of type A where you ought to have objects of type B ... according to the static typing. Some hole in the static typing is allowing the bad stuff to leak into the heap ... where it is liable to cause damage (e.g. unexpected ClassCastExceptions) at runtime.

It is not a particularly good analogy, but it is the terminology that the Java folks coined ... and they have (in effect) defined it in the page that you linked to, and probably other places.


But still - there should be a reason / mnemonic device behind that name.

Why should there be? There are lots of words and phrases in use in English where nobody really knows the origin or the reasoning. Or where the origin is known, but is illogical. For example, the supposed origin of the term "bug" referring to a flaw in a computer program. Or the current meaning of the term "quantum leap" in popular culture. Or the word "gay".

(But, in the case of "heap pollution", the source >>is<< known, and the reasoning behind the choice of the term >>is<< self evident ... to people from the same linguistic and cultural background as the authors.)

It is funny but even google does not seem to know why.

Not really. It just means that nobody had previously thought to ask for a definition in a place that Google indexes. 1) The usage is restricted to the Java programming AFAIK, and 2) the analogy is obvious ... to most people who would use the term.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy