« iCab 3.0.3 Beta 438 - Growl | Main | iWoz surfing with iCab »

Tue, Jan 16, 2007

Constructor Keyword?

In addition to my Java wish post two weeks ago, here's another idea for an extension of the current Java syntax. Beginners often have difficulties in finding the constructors of a class. Both you and I know that a constructor has no return type and uses the name of the class, but why not make this special code easier to find?

public class Example {
  public constructor Example() { ... }
}

This new constructor keyword could either be a new modifier that would be allowed only on "methods" without return type and with the same name as the class. Or it could be a special return type (like void) allowed only on methods with the same name as the class. The latter solution would have a second benefit: You cannot accidentally add the void return type to a constructor any more (which makes the intended constructor a plain method) - an error that is hard to track down especially by beginners.

Of course this could also be realized using annotations (e.g. "@Constructor"), but IMHO the coding of a constructor should be part of the syntax and not of the meta data.

Hey, maybe it's time to go to the Kitchen Sink and toy around with the Java syntax? :-)

Posted by Thomas Much at 12:20
Categories: Java