07/03/25 21:58:52
>>60
なるほど。それならこれでいけるかな。
ただ、その処理やるならkeyとクラス名を紐付けといてリフレクションで呼んだ方が楽かと。。
public interface IfCommand {
public void exec();
}
public OneTimeExecCommand implements IfCommand{
public void exec(){何かの処理}
}
public TwoTimeExecCommand implements IfCommand{
public void exec(){何かの処理}
}
public class MyModule implements Module {
public void configure(Binder binder){
binder.bind(IfCommand.class).to(OneTimeExecCommand.class)
.annotatedWith(OneTimeExec.class).in(Scopes.SINGLETON)
binder.bind(IfCommand.class).to(TwoTimeExecCommand.class)
.annotatedWith(TwoTimeExec.class).in(Scopes.SINGLETON)
}
}
pulic class CommandProcessor {
private @Inject @OneTimeExec IfCommand oneTimeExec;
private @Inject @TwoTimeExec IfCommand twoTimeExec;
public process(){
switch(key){
case 1:
oneTimeExec.exec();
case 2:
tweTimeExec.exec();
}
}