R
Robert
Hi,
According to the operator precedence table, the dot operator has a higher
precedence than the 'new' operator:
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/expressions.html
Therefore when I write
new myClass.method()
it should, according to this table, be parsed as
new (myClass.method())
which is nonsensical and doesn't compile.
It seems to be parsed as this instead:
(new myClass).method()
Is there an explanation?
****
sample code:
****
public class C {
public int i = 0;
public C(int i) {
this.i = i;
}
public int getI() {
return i;
}
public static void main(String args[]){
System.out.println(new C(20).getI());
// is parsed as:
//System.out.println( (new C(20)).getI() ); ==> ok
// but according to precedance table should be parsed as:
//System.out.println( new (C(20).getI()) ); ==> wrong
}
}
According to the operator precedence table, the dot operator has a higher
precedence than the 'new' operator:
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/expressions.html
Therefore when I write
new myClass.method()
it should, according to this table, be parsed as
new (myClass.method())
which is nonsensical and doesn't compile.
It seems to be parsed as this instead:
(new myClass).method()
Is there an explanation?
****
sample code:
****
public class C {
public int i = 0;
public C(int i) {
this.i = i;
}
public int getI() {
return i;
}
public static void main(String args[]){
System.out.println(new C(20).getI());
// is parsed as:
//System.out.println( (new C(20)).getI() ); ==> ok
// but according to precedance table should be parsed as:
//System.out.println( new (C(20).getI()) ); ==> wrong
}
}