W
www
Hi,
I have an Abstract class and other classes which are subclasses of it.
public abstract MyClass {
protected List _list;
public abstract void doIt();
}
public class ClassA extends MyClass {
public ClassA() {
_list = new ArrayList(); //this is mandatory since _list is not
implemented YET!
...//other things
}
public void doIt() {
double d = getList().get(1); //using super_list
}
..
}
public class ClassB extends MyClass {
public ClassB() {
_list = new ArrayList(); //this is mandatory since _list is not
implemented YET!
...//other things
}
..
}
It is kind of hard or tricky for anybody to remember, if you extend your
class from MyClass, be sure to add "_list = new ArrayList()". Actually,
I didn't know such a "requirement" and got null point exception when I
ran my program.
Should I do like this:
public abstract MyClass {
protected List _list = new ArralyList(); //now, the subclass no need to
implement it in their constructors
public abstract void doIt();
}
Thank you for your help.
Thank you very much.
I have an Abstract class and other classes which are subclasses of it.
public abstract MyClass {
protected List _list;
public abstract void doIt();
}
public class ClassA extends MyClass {
public ClassA() {
_list = new ArrayList(); //this is mandatory since _list is not
implemented YET!
...//other things
}
public void doIt() {
double d = getList().get(1); //using super_list
}
..
}
public class ClassB extends MyClass {
public ClassB() {
_list = new ArrayList(); //this is mandatory since _list is not
implemented YET!
...//other things
}
..
}
It is kind of hard or tricky for anybody to remember, if you extend your
class from MyClass, be sure to add "_list = new ArrayList()". Actually,
I didn't know such a "requirement" and got null point exception when I
ran my program.
Should I do like this:
public abstract MyClass {
protected List _list = new ArralyList(); //now, the subclass no need to
implement it in their constructors
public abstract void doIt();
}
Thank you for your help.
Thank you very much.