我不知道这是否可能,因此我需要您的帮助。 我想要做的是我想要添加对象到Vector。问题是这些对象是在另一个类中创建的。 这可能吗?在另一个类中创建的访问对象
这里是我的代码:
class Factory {
public Factory() {
Action run = new RunAction();
Action climb = new ClimbAction();
}
}
public class Game {
private Vector<Action> actions = new Vector<Action>();
public Game(Factory fact) {
actions.add(XXXX); ****//What to write here to add the actions created in Factory? Somehow I want to use fact for this.**
}
}
class ClimbAction extends Action {
public ClimbAction() {
super("Try to climb\n");
}
}
class RunAction extends Action {
public RunAction() {
super("Try to run\n");
}
}
class TestClass {
Factory f = new Factory();
Game game = new Game(f);
}
如果你冷静下来,你至少可以抽出时间来评论为什么请。 – rodit
是的,我想将所有的操作添加到Vector中。感谢您的建议,这对我帮助很大! – user2939293
@ user2939293没问题。很高兴我能帮上忙! – rodit