例如,我想創建一個具有指向某個方法的指針的數組。 這就是我想說的:我可以通過數組調用一個方法嗎?
import java.util.Scanner;
public class BlankSlate {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
System.out.println("Enter a number.");
int k = kb.nextInt();
Array[] = //Each section will call a method };
Array[1] = number();
if (k==1){
Array[1]; //calls the method
}
}
private static void number(){
System.out.println("You have called this method through an array");
}
}
對不起,如果我不是不夠,或者如果我的格式是錯誤的描述。感謝您的輸入。
創建一個像Runnable這樣的接口的數組(或列表)並執行'array [i] .run()'。 – 2014-09-20 01:23:01