Skip to content

Instantly share code, notes, and snippets.

@yum45f
Last active July 30, 2017 13:27
Show Gist options
  • Save yum45f/8fc767ac1b24df76a3b65bed5fab6b51 to your computer and use it in GitHub Desktop.
Save yum45f/8fc767ac1b24df76a3b65bed5fab6b51 to your computer and use it in GitHub Desktop.
パッケージ名がわからないクラスにあるメソッドを呼び出すプログラム。(一部抜粋)
package cl1;
import cl2;
//こっちは報告用にちょっと直しただけ。デバッグさえしてない。
public class class1 implements OBJInterface{
public static void main(String[] args) {
ObjectManager.addScript(new MainCode());
}
public static void start(){
System.out.println("成功!2");
}
}
package cl2;
import java.util.ArrayList;
//こういう風にやって解決(デバッグが通っただけでまだ動作は試してない。)
public class ObjectManager {
public ArrayList<OBJInterface> objects = new ArrayList<OBJInterface>();
public void addScript(OBJInterface obj){
objects.add(obj);
}
public void runStart(){//こいつをどっかで呼ぶ。
for(OBJInterface o :objects){
o.start();
}
}
}
package cl3;
public interface OBJInterface {
void Start();
void Update();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment