[871] in java-interest

home help back first fref pref prev next nref lref last post

"new" revisited

daemon@ATHENA.MIT.EDU (Scott Hudson)
Sat Aug 12 03:25:54 1995

From: hudson@cc.gatech.edu (Scott Hudson)
To: java-interest@java.sun.com
Date: Wed, 9 Aug 1995 21:43:03 -0400 (EDT)


I don't seem to be able to find the original message, but I recall that 
recently the precedence of the "new" operator was discussed and that, in
contrast to C++, apparently it is supposed to bind tighter than ".".  As I 
recall the particular example in question was something like: 
"new foo.bar().blee.bas" which is supposed to be legal and parse as: 
"(new foo.bar()).blee.bas".

Now if "new" has higher precedence than ".", and (per the spec) "." has
the same precedence as "[]", then this implies that "new" has higher 
precedence than "[]".  If this is the case, then I think we may have 
another ambiguity.  In particular, it seems like "new foo.bar[5][5][5]" by 
the same reasoning as the example above should parse as: 
"(new foo.bar[5])[5][5]" which can't be right since we could never allocate 
multidimensional arrays.  

Before saying something on the order of "[] is left associative", however, 
note that it gets a bit trickier.  Consider: "new foo.bar[5][][5]".  This one 
clearly must mean "(new foo.bar[5][])[5]".   (In fact making associativity
arguments here is dubious since "[]" acts as two different "operators" here.
The first two uses of "[]" are a declarative "operation" which is distinct 
from the third which is an array access operation.)  

This seems to argue for putting "new" precedence back at the level it is in
C++.  In that case both "new foo.bar().blee.bas" and  "new foo.bar[5][][5]"
would be illegal and the language would force the user to use explicit 
parenthesis (which results in more readable code, anyway).

Comments/discussion?

Scott
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post