One-sided instantiation (diamond, collection literals)

Barney Pitt barney at frontofficedeveloper.com
Tue Nov 3 03:05:09 PST 2009













Newbie apologies, 
            
                
                    
                    
                    reinierz at gmail.com has just pointed out that I have been replying to members without a CC to coin-dev! 

From: barney at frontofficedeveloper.com
To: markmahieu at googlemail.com
Subject: RE: One-sided instantiation (diamond, collection literals)
Date: Tue, 3 Nov 2009 10:56:28 +0000









I'm sure that in the first example you meant 

interface I {	String s();}class C {	String s = new String();}

as "s" could not be field in an interface. But I still don't really see what you're getting at. Shadowing an accessible method name or field name in a subclass/implementation is an appalling practise which should have been outlawed by the language from the off. But I don't see how my proposal makes the situation any worse.

Barney     


From: markmahieu at googlemail.com
Subject: Re: One-sided instantiation (diamond, collection literals)
Date: Tue, 3 Nov 2009 10:16:08 +0000
To: barney at frontofficedeveloper.com


Thanks for the reply.
What I mean though, is that the following currently legal example declares an interface and a class each with a field named 's':
interface I {	String s = new String();}class C {	String s = new String();}

Under your proposal, I could then change the above to:
interface I {	String s();}class C {	String s();}

In the interface, I now have a method called 's', yet in the class I've still got the field just using different declaration syntax.  That's highly inconsistent, in my opinion.
Regards,
Mark


On 3 Nov 2009, at 09:47, Barney Pitt wrote:
It would mean that your interface declares a method s() returning String.

Were it an abstract class, it would mean that your field s is initialized empty. 

I'm not sure I've ever seen a practical example of a Java class which wasn't written with fields declared first in a block and methods declared afterwards, although I confess that if you do mix abstract method declarations willy-nilly with field declarations the notation might confuse a newcomer. 

I'm more concerned with the everyday practicalities of succinct readable code - though of course I fully accept that readability is subjective.

Barney

CC: coin-dev at openjdk.java.net
From: markmahieu at googlemail.com
Subject: Re: One-sided instantiation (diamond, collection literals)
Date: Mon, 2 Nov 2009 22:52:13 +0000
To: barney at frontofficedeveloper.com


On 2 Nov 2009, at 22:27, Barney Pitt wrote:
Let me propose a simple language change which achieves this not only when declaring collections and generically defined objects, but for all cases where an object is declared and instantiated.
Any statement of the form
Foo foo=new Foo(myBar, myBaz);
can be replaced by
Foo foo(myBar, myBaz); 

OK, so what would this mean?
interface I {	String s();}

Regards,
Mark
Be one of the first to try Windows Live Mail.
 		 	   		  
Be one of the first to try Windows Live Mail. 		 	   		  
_________________________________________________________________
Be one of the first to try Windows Live Mail.
http://ideas.live.com/programpage.aspx?versionId=5d21c51a-b161-4314-9b0e-4911fb2b2e6d


More information about the coin-dev mailing list