67

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
79

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. The usage is restricted to the Java programming (as far as I am aware), and the analogy is obvious ... to most people who would use the term.

8 years later, this is still the only page that tries to answer the "why" question. I guess, "self evident" covers it adequately :-)

| improve this answer | |
  • It might be overstating the case to say nobody knows where the word "bug" comes from. The word "bug", and similar and related words like "bogey", all connote things that cause recurrent fear and annoyance and which play on the mind - evils in general. – Steve Mar 30 at 9:59
  • The origin of "computer bug" is ... complicated. And there are various versions; see interestingengineering.com/the-origin-of-the-term-computer-bug. Some of them relate to insects ... which is not exactly logical. So I reckon it is a good example of a term where nobody really knows the reasoning. But it doesn't matter. It is just an example to illustrate a point ... not prove one. – Stephen C Mar 30 at 10:15
  • I'm not sure how the origin is illogical according to the general definition I've given, of recurrent and fearsome annoyances and non-specific evil. So far as the word "bug" connotes the involvement of an insect, nowadays we tend to think of mildly annoying cases such as a fly buzzing around the ceiling until chased out, rather than the truly fearsome and disgusting cases such as opening the breadbin in the morning and finding cockroaches eating the loaf, or opening the flour tin and finding weevils and centipedes. – Steve Mar 30 at 10:26
  • Centipedes are not insects :-) Anyhow, I have noted your opinion but don't propose to change my answer. Nits are not insects either :-) – Stephen C Mar 30 at 10:28
  • But they are recurrent and fearsome annoyances to the Victorian-era householder. I return to my point that, far from being of unknown origin, the word "bug" belongs to a class of etymologically and phonetically related words whose uniting theme is recurrent and fearsome annoyances, or evil (without implying a specific form). – Steve Mar 30 at 10:37