One-sided instantiation (diamond, collection literals)
Mark Mahieu
markmahieu at googlemail.com
Tue Nov 3 14:02:40 PST 2009
Barney,
No apology needed - like most mature languages, Java has its share of
dark forgotten corners, and they've certainly caught me out when I've
ventured into this arena.
But more importantly I think it's great that you're willing to try
modifying the compiler to investigate your ideas. Please continue to
do so.
Cheers,
Mark
On 3 Nov 2009, at 11:33, Barney Pitt wrote:
>
>
>
> From: barney at frontofficedeveloper.com
> Subject: RE: One-sided instantiation (diamond, collection literals)
> Date: Tue, 3 Nov 2009 11:30:25 +0000
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> My sincere apologies Mark, I had completely forgotten that
> interfaces can declare static fields without the keyword static. I
> haven't seen it done in years.
>
> Personally I'd include that case as "shadowing" and a dreadful
> practice which should be outlawed - but I don't have a ready
> solution as to how it would work with my proposal :(
>
> From: markmahieu at googlemail.com
> Subject: Re: One-sided instantiation (diamond, collection literals)
> Date: Tue, 3 Nov 2009 11:04:00 +0000
> To: barney at frontofficedeveloper.com
>
>
> No, I meant what I wrote. The following is perfectly legal in Java:
> interface I { String s = new String();}
>
> This has nothing to do with shadowing.
> Mark
>
>
> On 3 Nov 2009, at 10:56, Barney Pitt wrote:
> 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