idle language change suggestion #243

hi,

how about some syntactic sugar that allows DefaultMutableTreeNode dmtn =new DefaultMutableTreeNode(userObject,true)

to be shortened toDefaultMutableTreeNode dmtn(userObject,true);

or is this trivial beyond belief? :)

asjf

[358 byte] By [asjf] at [2007-9-30 19:38:00]
# 1
I think it is not too bad an idea, but I think it could lead to some confusion.If this was instantiated outside a method body it could itself look a bit like a method declaration at first glance. Jim
coventryjim at 2007-7-7 0:22:58 > top of Java-index,Java Essentials,Java Programming...
# 2
Exactly. You've just declared an abstract or an interface method...//Håkan
hakgu at 2007-7-7 0:22:58 > top of Java-index,Java Essentials,Java Programming...
# 3

good pointclass Foo {

DefaultMutableTreeNode dmtn(userObject,true);

}

does look like a method at first glance (of course technically it couldn't be one - even abstract since the parameter type declarations are missing)

a slightly longer version might get round this?class Foo {

DefaultMutableTreeNode dmtn = new(userObject,true);

}

asjf

asjf at 2007-7-7 0:22:58 > top of Java-index,Java Essentials,Java Programming...
# 4

> a slightly longer version might get round

> this?class Foo {

> DefaultMutableTreeNode dmtn = new(userObject,true);

> }

asjf

So have you just created a new instance of DefaultMutableTreeNode? (is that the default?) Because:

List l = new ArrayList();

List l2 = new LinkedList();

List l3 = new Vector();

List l4 = new() // ?

YoGee at 2007-7-7 0:22:58 > top of Java-index,Java Essentials,Java Programming...
# 5

the difference with this example is that the type of the reference being assigned to is an interface - the suggested syntax contraction would only work for concrete classes i guess

in the case of assigning to an interface then there is no redundancy in the declaration as both the reference type and the class type are valuable information

asjf at 2007-7-7 0:22:58 > top of Java-index,Java Essentials,Java Programming...
# 6
Object o = new String();?
YoGee at 2007-7-7 0:22:58 > top of Java-index,Java Essentials,Java Programming...
# 7

> > Object o = new String();

>

> ?

ah.. i wasn't suggesting getting rid of the long form - so you'd still be able to do what you've written above

this suggestion was purely because the other afternoon I found myself writingFile file = new File("sdfsdjklfjsdkl");

and similar things lots of times

asjf at 2007-7-7 0:22:58 > top of Java-index,Java Essentials,Java Programming...
# 8

> ah.. i wasn't suggesting getting rid of the long form

> - so you'd still be able to do what you've written

> above

>

> this suggestion was purely because the other afternoon

> I found myself writingFile file = new

> File("sdfsdjklfjsdkl");

and similar things lots

> of times

Hmm, sorry but I don't like it (just my opinion)

YoGee at 2007-7-7 0:22:58 > top of Java-index,Java Essentials,Java Programming...