3

我试过这样做:

var r = {};
for (p in Packages) {
  if (Packages.hasOwnProperty(p)) {
    r[p] = p.toString();
  }
}

...但我得到一个错误:

TypeError: Invalid iterator value ... at line xx

错误消息中指示的行是带有

for (p in Packages) { ... } 

还,

var r = {
  "Packages" : typeof Packages,
  "Packages.length" : typeof Packages.length,
  "Packages.java" : typeof Packages.java,
  "Packages.surelyThisIsNotDefined" : typeof Packages.surelyThisIsNotDefined
};

结果是:

{
  "Packages": "object",
  "Packages.length": "object",
  "Packages.java": "object",
  "Packages.surelyThisIsNotDefined": "object"
}

...这根本没有帮助。

4

1 回答 1

2

不确定您想要的输出格式,以下代码返回 ClassLoader 在运行时加载的 Java 包的列表:

packs = java.lang.Package.getPackages()
for (p in packs) 
print(packs[p]);
于 2013-04-03T19:48:16.270 回答