我有一个演员在某个时间加入舞台。并且在将其添加到阶段之后需要计算值。 在将某个回调添加到舞台后,有没有办法向Actor添加回调?
示例代码
comm -12 <(grep -Ev $'^[ \t]+$' file1 | sort) <(grep -Ev $'^[ \t]+$' file2 | sort)
示例阶段添加代码
public class SlotReel extends Table{
public SlotReel() {
}
public void compute(){
//call after SlootReel is added to stage
}
}
答案 0 :(得分:0)
实施例
public class Solution {
// Create interface
interface Computable {
void compute();
}
// SlotReel implement Computable interface
static public class SlotReel implements Computable {
String name;
public SlotReel(String name) {
this.name = name;
}
// Implement compute method
@Override
public void compute() {
// call after SlootReel is added to stage
// Just an example
System.out.println("Hello " + name);
}
}
static public class Stage {
List<Computable> list = new ArrayList<>();
public void addActor(Computable slot) {
list.add(slot);
// call compute method
slot.compute();
}
}
public static void main(String[] args) {
Stage stage = new Stage();
stage.addActor(new SlotReel("A"));
stage.addActor(new SlotReel("B"));
stage.addActor(new SlotReel("C"));
stage.addActor(new SlotReel("D"));
}
}