Sun’s rejection of Delegates for Java

In 1998 Microsoft introduced a variant of Java called Visual J++ that included delegates, basically type-safe function pointers. Anders Hejlsberg was very involved with their development, and he went on to add them to C#.

This occurred against backdrop of a war between Sun and Microsoft, much of it over the non-compliance of the MS Java implementation with Sun’s license terms.

Sun rejected the idea of delegates, and a whitepaper attributed to “The Java Language Team”  [http://java.sun.com/docs/white/delegates.html]  was published justifying this decision on technical grounds, in no uncertain terms. Here the gist of its message:

“The newest version of the Microsoft Visual J++ development environment
supports a language construct called delegates or bound method
references
. … It is unlikely that the Java programming language will
ever include this construct. … bound method references are unnecessary
and detrimental to the language…. bound method references are
harmful because they detract from the simplicity of the Java
programming language and the pervasively object-oriented character of
the APIs. ”

Java’s Alternative: Interfaces and Inner-classes?

The whitepaper describes what became the “Java-way” of representing pointers to functions

  • One interface is defined for each function signature, eg String => Integer
  • One inner class adapter is written that implements the interface and bridges the call to one underlying method being invoked.

The problem was, delegates (and similar ideas – functions-as-values, closures, blocks, lamdas) have proven to be a much more flexible and elegant than the Java-way. They are supported in virtually every language to become successful in the last decade. Except  Java, the worlds most popular language, still lacks them, much to many peoples frustration.

So, how did Sun get it wrong? They were presented a working implementation of with what’s now recognized as a good solution, but spurned it in favor of an inferior alternative.

The power of group allegiances to affect human judgment and clear thinking

Anders proposed a good idea for Java, but he worked at Microsoft.  It seemed the Sun-MS rift prevented technical people at Sun seeing, or perhaps admitting, that the delegate concept of a typesafe function-pointer had genuine merit.

The underlying tendency to unconsciously prefer ideas that originate from people in allied groupings, organizations or cultures, regardless of actual content, is very widespread (certainly not confined to Sun, as at minimum it afflicts me too). History is full of examples. While it encourages intra-group harmony and consistency, it interferes with our ability to distinguish truth from untruth, and thus slows our learning and progress, and ultimately, reduces our intelligence.

In this case, Java was a casualty of polarised group-think between two warring corporations.