让我先说,我DID搜索几个小时,但没有找到我需要的确切内容.
我需要运行类(应用程序)数组并使用当前应用程序的变量和方法.
public class App {
public final Integer number = 0;
}
public class Player extends App {
public final Integer number = 1;
}
public class Navigation extends App {
public final Integer number = 2;
}
public class Phone extends App {
public final Integer number = 3;
}
private ArrayList<App> apps = new ArrayList<App>();
apps.add(new Player());
apps.add(new Navigation());
apps.add(new Phone());
Run Code Online (Sandbox Code Playgroud)
如果我做
apps.get(0).number // = 0
Run Code Online (Sandbox Code Playgroud)
我得到父母(app)的号码
如果我把它投给玩家
(Player) apps.get(0).number // = 1
Run Code Online (Sandbox Code Playgroud)
我得到了理想的结果
现在,我想在应用程序的多个位置运行所有N个应用程序(可能超过3个),但我不想这样做:
if (gun …Run Code Online (Sandbox Code Playgroud)