By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,542 Members | 1,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,542 IT Pros & Developers. It's quick & easy.

operator precedence

P: n/a
Hi,
According to the operator precedence table, the dot operator has a higher
precedence than the 'new' operator:
http://java.sun.com/docs/books/tutor...pressions.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*precedence*table*should*be*parse d*as:*
********//System.out.println(*new*(C(20).getI())*);*==>*wron g*
****}
}
--
Rob
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
The question was answered by John Bollinger in c.l.j.programmer.
The answer is that the precedence table is wrong in this case.
Sorry for the cross-post.
--
Rob
Jul 17 '05 #2

P: n/a
Liz

"Robert" <no****@yahoo.com> wrote in message
news:40***********************@news.skynet.be...
The question was answered by John Bollinger in c.l.j.programmer.
The answer is that the precedence table is wrong in this case.
Sorry for the cross-post.
--
Rob


Seems to me that the table is not wrong. It is not possible
to use 'new' to create a new method, just a class. So when
you say you want a new method, you get the whole class too.
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.