Last active
July 30, 2017 13:27
-
-
Save yum45f/8fc767ac1b24df76a3b65bed5fab6b51 to your computer and use it in GitHub Desktop.
パッケージ名がわからないクラスにあるメソッドを呼び出すプログラム。(一部抜粋)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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