【发布时间】:2014-11-14 15:52:18
【问题描述】:
例如,我想创建一个数组,其中包含调用方法的指针。 这就是我想说的:
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()。