Abstrakcyjna klasa Value wygląda tak:
public abstract class Value {
public abstract String toString();
public abstract Value add(Value v);
public abstract Value sub(Value v);
}
Klasa Integer, która po niej dziedziczy:
public class Integer extends Value implements Cloneable{
final int val;
public Integer(){this.val = 0;}
public Integer(int a){
this.val=a;
}
@Override
public String toString() {
return String.valueOf(this.val);
}
@Override
public Value add(Value v) {
int value = 0;
if (v instanceof Integer) {
Integer parsedValue = (Integer) v;
value = this.val + parsedValue.val;
}
return new Integer(value);
}
}
Chcę w mainie wywołać konstruktor DataFrame, który przyjmuje tablicę obiektów Value:
public class Main {
public static void main(String[] args) {
Str s = new Str();
DateTime d = new DateTime();
Integer i1 = new Integer();
Integer i2 = new Integer();
File file = new File("groupby.csv");
new DataFrame("groupby.csv", new Value[]{s, d, i1, i2}, true, new String[]{"id", "date", "total", "val"});
}
}
Czy to jest poprawne?