例如,我想创建一个具有指向某个方法的指针的数组。 这就是我想说的:我可以通过数组调用一个方法吗?
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