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.

11 Years
Discussion Span
Last Post by alba07

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.