Reputation: 65
I'm trying to do my current project at my university, and I'm given an abstract class Value, and I'm needed to change basic types: int, string, object(map) and array(list) into Value. Value is made into an abstract constructor, and I need to create four different extended classes from Value. Each extended class will be able to get one of the types and convert into Value. added is the code I made for the get method, I want to know if it's possible to return the Value as it is below...
public class Number extends Value {
private Number k;
public Number(Number k)
{
super();
this.k = k;
}
public Value get(int i) {
this.k=i;
return this;
}
}
The following is the super class given by the university...
public abstract class Value
{
public abstract Value get(int i);
public abstract Value get(String s);
}
Upvotes: 2
Views: 51
Reputation: 1042
You can use some thing like this
public abstract class Value {
public abstract Value get(int i);
public abstract Value get(String s);
}
public class Number extends Value {
private Number k;
private Object o;
public Number(Number k) {
super();
this.k = k;
}
@Override
public Value get(int i) {
this.k.o = i;
return this;
}
@Override
public Value get(String s) {
this.k.o = s;
return this;
}
}
Upvotes: 1