Вот моя ситуация
public abstract class Actions {
public static Actions STAND;
public static Actions ATTACK;
public static Actions COLONIZE;
public static Actions DEFEND;
public static Actions TURN_CW;
public static Actions TURN_CCW;
public static Actions DIE;
public abstract long[] getFramesDurations();
public abstract int[] getBaseTiles();
}
public class SimpleActions extends Actions{
public static Actions STAND = new SimpleActions( new long[]{120,120,120,120,120,120,120}, new int[]{0,1,2,3,4,5,6});
public static Actions ATTACK = new SimpleActions( new long[]{120,120,120,120,120,120,120,120,120}, new int[]{7,8,9,10,11,12,13,14,15});
public static Actions COLONIZE = new SimpleActions( new long[]{120,120,120,120,120,120,120}, new int[]{7,8,9,10,11,12,13,14,15});
public static Actions DEFEND = new SimpleActions(new long[]{1}, new int[]{1});
public static Actions TURN_CW = new SimpleActions( new long[]{1}, new int[]{1});
public static Actions TURN_CCW = new SimpleActions( new long[]{1}, new int[]{1});
public static Actions DIE = new SimpleActions( new long[]{1}, new int[]{1});
private final long[] mActionFramesDurations;
private final int[] mActionBaseTiles;
SimpleActions(long[] pActionFramesDurations, int[] pActionBaseTiles) {
mActionFramesDurations = pActionFramesDurations;
mActionBaseTiles = pActionBaseTiles;
}
public long[] getFramesDurations()
{
return mActionFramesDurations;
}
public int[] getBaseTiles()
{
return mActionBaseTiles;
}
}
public abstract class A<T extends Actions> {
A() {
doSomething(T.STAND);
}
protected void doSomething(Actions action) { use action somewhere}
}
public class B extends A<SimpleActions> {
B() {
super();
}
}
Я всегда получаю nullPointerException, когда конструктор A вызывает doSomething, потому что action имеет значение null ..
Поскольку B расширяет A, я ожидал, что он будет использовать SimpleActions.STAND, а не Actions.STAND.
Что я делаю не так? Как мне это сделать?