∞ Thank Gosling
The following is not legal Java:
public static void main (String[] args) {
int[] foo = new int[1];
int[] bar = new int[1];
((args.length == 0) ? foo[0] : bar[0]) = 1;
}
That makes my life easier.
| samskivert » Thank Gosling |
November 4, 2009∞ Thank GoslingThe following is not legal Java:
public static void main (String[] args) {
int[] foo = new int[1];
int[] bar = new int[1];
((args.length == 0) ? foo[0] : bar[0]) = 1;
}
That makes my life easier.
2 Responses to “Thank Gosling” |
Bits Ludography Reviewlets Camera Wrestling
2009/01 - Brazil, Argentina
2008/08 - Burning Man 2008/06 - Trans-Siberia 2006/12 - New Orleans 2004/08 - Burning Man 2004/04 - Nepal Himalayas 2004/03 - Kamakura 2004/02 - Mitake-san 2002/07 - 日本 2001/12 - Jamonduras 2001/08 - Burning Man 2001/04 - Italy 2000/12 - Morocco 2000/09 - New Zealand 2000/08 - Burning Man 2000/06 - Chickens! 1999/12 - Fiji Archives: | ||||||||||
| samskivert.com | ©2001 - 2009 Michael Bayne <mdb@samskivert.com> |
The 2nd and 3rd operands to the ternary operator must be values, not variables.
Your particular example could be done similarly as:
// legal
((args.length == 0) ? foo : bar)[0] = 1;
But:
// not legal
((args.length == 0) ? foo : bar) = new int[1];
Yeah, that turns out to be very useful for my current purposes, which is that I have an AST and I’m looking at the assignment operator and I want to know of the left-hand side is an array select or not. Clearly the left child of the AST could just be an array select and I’m fine, but I was wondering when I might need to traverse the left-tree to go looking for a select.
I believe that the only time I need to do that is if the left-hand side is a Paren node. The following is legal:
(foo[3]) = 5;
But AFAIK the only thing I need to worry about is parens. No other expression on the left-hand side can evaluate to a variable into which I will store a value. Probably I’m missing something. :)