java - Why can't I initialize an abstract class's method without changing them to static? -
this question has answer here:
i'm taking tutorial on building simple behavior ai. it's 'brain' class abstract , contains states in "running","success","failure". in ai unit - droid class have method start droid up
public void update(){ if(routine.getstate()==null){ routine.start(); } routine.act(this, board); }
eclipse tells me methods routine not valid because:
cannot make static reference non-static method getstate() type routine
which can getstate have change routinestate static well, can't start or act containt this.
this brain of ai far:
public abstract class routine { public enum routinestate{ success, failure, running } public routinestate getstate(){ return state; } protected routinestate state; protected routine() { } public void start(){ this.state = routinestate.running; } public abstract void reset(); public abstract void act(droid droid, board board); public void succed(){ this.state = routinestate.success; } public void fail(){ this.state = routinestate.failure; } public boolean issuccess(){ return state.equals(routinestate.success); } public boolean isfailure(){ return state.equals(routinestate.failure); } public boolean isrunning(){ return state.equals(routinestate.running); } }
if state
class field, should static below.
otherwise, you'll need object own state.
public static routinestate getstate(){ return state; } protected static routinestate state;
Comments
Post a Comment