如何自动创建 class 的新实例?

How to create new instance of class automatically?

基本上我有 类,例如 Main & Page。无论如何,是否可以根据程序检测到我需要的页面数量(基于它能够解析的关键短语数量)自动创建新的页面类型

EX:说关键短语出现了 4 次。我希望每个页面都有一个新页面 object,自动标题为 Page + #.

执行此操作的最佳方法是页面数组 Class。

public Page foo[];

...
public void createPages(int pages){
    foo = new Page[pages]; //makes pages # of Pages in the array
    foo[index] = new  Page(fee, faa, foe);
}

这将允许您使用 foo[index]... 访问每一个 new Page(fee, faa, foe) 允许使用数组构造函数。