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.

12 Comments

  1. Leany said,

    March 3, 2009 at 4:33 pm

    Just dropping by.Btw, you website have great content!

    ______________________________
    Have You Ever Stayed Awake at Night Stressing About Whether or Not Your Marriage Will Last … And What You Can Possibly Do to Save It?

  2. EricT said,

    March 14, 2011 at 4:47 pm

    Great post.

  3. Andrew K said,

    August 25, 2012 at 1:36 pm

    I disagree, and kudos Sun for not implementing delegates, and hope Oracle will not do it either. Delegates are a redundancy polluting object-oriented paradigm. Most of the posts on the subject are missing a big picture. With delegates Microsoft attempted to retrofit pure object-oriented programming back into functional, thus making the landscape more intuitive/acceptable to programmers with C/C++ background. Such decisions are driven by marketing rather than an engineering wisdom.

  4. Steve H said,

    November 9, 2012 at 8:46 am

    To say that Java is “pure object-oriented programming” is a bit of an overstatement. Java does not have true polymorphism, in that it cannot extend multiple objects without interfaces. Because I cannot extend A & B, I am forced to “implement” A & B with delegate methods, which is cumbersome to code.

    I would very much like something along the lines of:

    class SomeClass implements SomeInterface, OtherInterface {
    delegate SomeInterface A;
    delegate OtherInterface B;
    ….
    }

    Instead of generating delegate classes for EVERY SINGLE METHOD in each of the Interfaces. This would not affect compilation, just syntax.

  5. Steve H said,

    November 9, 2012 at 8:46 am

    “delegate classes” ==> “delegate methods”

  6. benhutchison said,

    November 9, 2012 at 9:13 am

    Use scala. Traits provide what you are after.

  7. Jose said,

    January 24, 2013 at 2:03 am

    Nice article, especially when going to the root of the problem, attitudes that reduce intelligence..
    Thanks!

  8. Eric T said,

    June 9, 2013 at 4:41 pm

    > Microsoft attempted to retrofit pure object-oriented programming back into functional, thus making the landscape more intuitive/acceptable to programmers with C/C++ background

    None of this makes any sense. Neither C nor C++ are functional languages, neither has closures, and neither Java nor C# are “pure object-oriented”. It has nothing to do with “intuitive to C programmers”, it’s a matter of pointless verbosity and lack of expressiveness.

    For instance, to pass a Comparator to a Sort in Java I have to write tons of irrelevant boiler plate nonsense to wrap up a few characters of actually meaningful code. It’s just *noise*, it adds nothing. With a closure, I’m still passing a callable object, I just don’t have to pollute the conceptual space with irrelevancies.

  9. October 30, 2014 at 7:11 am

    […] http://msdn.microsof…v=vs.60%29.aspxhttp://benhutchison….gates-for-java/https://weblogs.java…ngly_types.htmlhttp://java.sys-con.com/node/49097 […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: