Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Left hand must be a variable

Tags:

java

If i do this it works

elements.getElement(j).getValues().getArray()[i]=(elements.getElement(j).getValues().getVariable(i)-minimum)/(maximum-minimum);

But if I do this it tells me that he left side should be a variable

elements.getElement(j).getValues().getVariable(i)=(elements.getElement(j).getValues().getVariable(i)-minimum)/(maximum-minimum);

The two functions are

double[] getArray(){
    return array;
}

double getVariable(int position){
    return array[position];
}

I believe that what is in the front does not matter and it is working properly and the mistake must lie somewhere at the end. And how come when I assign let's say like this ( 1st row) it works , which means it is a variable but when I try to assign something to it like(2nd row) it does not work.How dumb am I ? What am I missing ?

double max=elements.getElement(j).getValues().getVariable(i);
elements.getElement(j).getValues().getVariable(i)=0.0;
like image 955
myheadhurts Avatar asked Dec 09 '22 03:12

myheadhurts


1 Answers

getVariable(i)

Is definitely different from

getArray()[i]

The first one returns an array, which may be indexed by [] and then used as a valid l-value. The latter returns a value (r-value), that can only be used on the left side of an assignemnt.

In simple words, you can not assign a value to a value, but you can assign a value to a memory location specified by an array and an index.

0 = 5 // this just won't work
array[0] = 5 // this will, because array[0] is a valid l-value

You may, however, create a method that would serve as a setter.

void setVariable(int position, double value) {
    array[position] = value;
}

It would be used like this

elements.getElement(j).getValues().setVariable(i, value);
like image 158
user35443 Avatar answered Dec 11 '22 10:12

user35443