-
-
Save ahirusp/eedc384f71fa5d5cb90a7e1cab1a7621 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 cl4; | |
public class class1{ | |
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 cl4; | |
public class class2{ | |
public static void main(String[] args){ | |
//ScratchやUnityではステージがキャラクタを管理してくれているので、あたかも | |
//知らないオブジェクト同士が通信できているように見えるけど、自前でやる場合は | |
//誰かがオブジェクトの一覧を管理する必要があります。 | |
// | |
//基本は配列(リスト)に登録していく感じですが、なんでもかんでも登録できてしまうと | |
//ややこしいので、インターフェースを決めておいて、各キャラクタのクラスは決められた | |
//メソッドを実装し、オブジェクトを管理しているクラスがまとめて呼び出しを行います。 | |
List<IGameObject> objects = new ArrayList<IGameObject>(); | |
objects.add(new cl1.class1()); | |
objects.add(new cl3.class3()); | |
for(IGameObject o in 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; | |
import cl4; | |
public class class3 implements IGameObject{ | |
public void start(){ | |
System.out.println("成功!:3"); | |
} | |
} |
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 cl4; | |
public interface IGameObject { | |
void start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
雰囲気で書いたのでコンパイルは通らないかもしれない・・