Java Addict
Java Addict

Reputation: 175

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

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;
}

Upvotes: 3

Views: 1383

Answers (1)

nanofarad
nanofarad

Reputation: 41281

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?

Upvotes: 4

Related Questions