I have a class
public class ValueObject<T> {
private T value;
public void setValue(T value){
this.value = value
}
}
In another class I have an Array of the Objects from the first Class
ArrayList<ValueObject<?>> valueObjects = new ArrayList<>();
ArrayList<String> valueNames = new ArrayList<>();
now I want to write a Method which looks in a second array for a name and assigns a new value to an instance of the first object in that arrayList
ValueObject<?> get(String name) {
return valueObjects.get(valueNames.indexOf(name));
}
public <T> void set(String name, T value) {
get(name).setValue(value);
}
But I don't get this to work. Do I need to write something with ? in the set() Method?
Thanks
value = valueshould bethis.value = valueStringvaluebut you callsetwithInteger, how would compiler be able to prevent it?ValueNames? And what'svalueNames? And why are you passing one instance to another? And why do you think you can callsetValue()with anyT?