I have two methods in the Item
Class:
public void setValue(String v);
public void setValue(Double v);
and I want to use Conditional Operator to setVAlue
in another class:
String str = ...
Double dbl = ...
item.setValue((condition) ? str : dbl);
but compiler says:
cannot find symbol
symbol : method setValue(java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>)
I think compiler uses the nearest common superclass (super interface) of Double and String as type of conditional Operator. but why?
See Question&Answers more detail:os