I have the following class and I am now supposed to add a parameter T, so that the value of Variable <T> is of type T rather than object.

I am now lost with this and need some help. Not getting the generic classes.

public class Variable {

private Object value;
private String name;

public Variable (String aname, object avalue){
name = aname;
value = avalue;
}

public String getName (){ return name; }

public Object getValue() {return value;}

public void setValue ( Object nvalue ){

value = nvalue;

}
public String toString (){

return name + " = " + value;

}
}

Thanks in advance.

Recommended Answers

All 2 Replies

Member Avatar for iamthwee

Thanks for the resource. If I am understaning this right I now can write:

public class Variable<T>{ (etc). or does Variable extend <Variable T>. I am sorry I am still a bit lost, I am new to generics and the more I read about them the more confused I seem to get.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.