can you please explain me why the following piece of code doesn't increment the element resulted from an array extraction on a specific position.
public class ArrayTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
int i =1;
int x = getArray()[i]++;
System.out.println(x); // it should not be 10 displayed, instead of 9 as it is?
}
public static int[] getArray (){
return new int [] {1,9,8,};
}
}
The value of local variable i should not be increased to 10 when it's displayed after post incrementation?
I understand how post and pre increment works. You post increment a value and next time it will call it it will have that value updated. Moreover if u pre increment a value the value is incremented and new value is updated on spot. However in my case the value is not updated when at next call, as it should be with post incrementation.
I am missing something, it's something different with returning from an array ?
Sincerely,