473,385 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

operator precedence

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
2 1703
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Master of C++ | last post by:
Hi, This is a simple question. In the following example, .. class Vector .. { .. private: .. int *Numbers; .. int vLength; ..
20
by: Vivek N | last post by:
Hi Folks, This question may well have been asked and answered before. But, sorry that I couldn't find one from the archives. I typed up this program and compiled it with gcc 3.3.2 main() { int...
4
by: mux | last post by:
Hi I found out that the following piece of code throws an error. 1 #include "stdio.h" 2 3 int main() 4 { 5 int a,b; 6 a= 10;
17
by: Anoob | last post by:
Can we consider () unary operator when calling a function, in exps eq. f(), ( 1 + 2). But when we call function f( 10 ) it is a binary operator. Even if we pass f( 10, 20) as we are using ,...
21
by: siliconwafer | last post by:
Hi, In case of following expression: c = a && --b; if a is 0,b is not evaluated and c directly becomes 0. Does this mean that && operator is given a higher precedence over '--'operator? as...
56
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
9
by: marko | last post by:
/* code start */ int a = 0; /* expected evaluation and excution order with precedence in mind /* False(3) , True(1), False(2) */ if ( (a=1) == 0 || 0 != 1 && (a =2) == 1) putchar('T');...
5
by: paulo | last post by:
Can anyone please tell me how the C language interprets the following code: #include <stdio.h> int main(void) { int a = 1; int b = 10; int x = 3;
8
by: subramanian100in | last post by:
Consider int i = 10; Why do we say that ++i yields an Lvalue and i++ yields an Rvalue ? I thought both these expressions yield only values. I am unable to understand the difference
6
by: newbie | last post by:
I have a script given to me by a co-worker to convert into VB; I can get the same results but I cannot fully understand the logic here... can someone please help me write this in a more...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.