Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Compile Error: Unexpected Type required: variable found: value

Tags:

java

I'm getting this Java Compile Error: "Unexpected Type required: variable found: value".

I realize in general, this means I'm probably doing something like 1.0 = mydouble; That's backwards. But, I'm not seeing my error in this code:

private Double bid;

public void setBid(double bid) {
    Double.isNaN(bid) ? this.bid = 0.0 : this.bid = bid;
}
like image 803
Java Addict Avatar asked Nov 21 '25 00:11

Java Addict


1 Answers

A ternary operator can only operate conditionally on values, not entire statements. Therefore, you would need to rewrite your code as:

this.bid = Double.isNaN(bid) ?  0.0 : bid;

Also, do you have a specific need to declare the field bid as a java.lang.Double (reference type) and not the primitive double?

like image 169
nanofarad Avatar answered Nov 22 '25 14:11

nanofarad