Forums Register Login

JQ+ Arrays[0]++

+Pie Number of slices to send: Send

I thought arrays were objects and the ++ operator only worked with primatives... so why can you use the ++ operator on a array object element?
+Pie Number of slices to send: Send
 

Originally posted by Dominic Mack:
I thought arrays were objects and the ++ operator only worked with primatives... so why can you use the ++ operator on a array object element?


Array is an object, but 0th element of the array is an int, which is a primitive. The unary operator ++ works on this int value, which happens to be the 0th element of an array.
HTH,
- Manish

[This message has been edited by Manish Hatwalne (edited October 12, 2001).]
+Pie Number of slices to send: Send
If the unary operator works on an int like you said, and
go() returns an int, why can't I do this???
int i = this.go()++;
[This message has been edited by Dominic Mack (edited October 12, 2001).]
+Pie Number of slices to send: Send
postfix or prefix increment works for variables only.
An element of array is evaluated to a "variable", while
a call to a method is evaluated to what is returned.
Since go() returns an int "value", you can't apply ++
to it.
Here is a quote from JLS:


JLS 15.13 -
The result of an array reference is a variable of type T, namely the variable within the array selected by the value of the
index expression.
JLS 15.14.1 -
A postfix expression followed by a ++ operator is a postfix increment expression. The result of the postfix expression
must be a variable of a numeric type, or a compile-time error occurs.



[This message has been edited by Nain Hwu (edited October 13, 2001).]
Replace the word "snake" with "danger noodle" in all tiny ads.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1259 times.
Similar Threads
Question Mock
ints and arrays........
pass by value
Incrementor operator
a confused concept
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 05:30:59.