I have two methods in the Item Class:
public void setValue(String v);
public void setValue(Double v);
and I want to use Cond
IF you want to go with the ternary operator only following code will solve your problem. For testing I have put false as the default value you can put your conditional expression.
public class st1 {
public static void main (String []args) {
Item i = new Item();
i.setValue (false?"test":0.0);
}
}
class Item {
private String str;
private double d;
public void setValue (Object str) {
try {
d = Double.parseDouble (str.toString());
System.out.printf ("Double type : %f", d);
} catch (NumberFormatException ne) {
this.str = str.toString();
System.out.printf ("String type : %s", this.str);
}
}
}