.java

musings on java and object oriented software development

Tuesday, August 28, 2007

Implicit declaration / short instance creation in Java 7

So today I'm reading Alex Miller's blog about proposed features of Java 7. I noticed something he refers to as "Short instance creation" and has a few links to other bloggers. I then notice some of the dates on the linked blogs, some in 2006, some in 2007.

I'm thinking "hang on, didn't I post something, somewhere, about this ages ago?".

So I googled for "implicit declaration java distiller" and, sure enough, I'd posted to a Sun forum about new language features in October 2004. 2004 !

I'm not suggesting that I was the first to ever write this, but way back on October 7 2004 I posted to that forum about the ":=" syntax and got shot down from folks who thought the world would end if such evilness was ever brought into the language. I honestly hadn't seen that syntax or read about the concept anywhere before that, but I'd implemented it in the now defunct project UCL (Universal Class Language) about 5 or 6 years ago.

Even James Gosling is suggesting it !

I still think it is good idea.

----------
Objectopia.org

1 Comments:

At 3:12 PM, Anonymous Anonymous said...

This is normally called "type inference for local variables", or some variation on that. ML and ML-derived languages do this (and have done this forever), but so do many recent Java-like languages. For example, in the Scala programming language, you can write:

val people = new Thing()

(I prefer this syntax over the ":=" syntax because it looks more like a variable declaration.)

Other Java-like languages that have this feature: Nice, Nemerle, C# 3.0, D.

Type inference has been around forever and I guarantee you the people in charge of Java have known about it. However, for the longest time, they'd say stuff like "we want to keep Java a simple language and, trust us, you really don't want that feature".

But things changed after C# came out. The people at Microsoft don't seem to be similarly afflicted with an irrational aversion to language improvements. The C# language makes significant progress with every revision. All of a sudden, the Java stewards have become more amenable to huge changes like closures.

 

Post a Comment

<< Home