我试过这样做:
var r = {};
for (p in Packages) {
if (Packages.hasOwnProperty(p)) {
r[p] = p.toString();
}
}
......但我收到了一个错误:
TypeError:无效的迭代器值...在第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"
}
......这根本没有帮助。
答案 0 :(得分:2)
不确定所需的输出格式,以下代码返回运行时由ClassLoader加载的Java包列表:
packs = java.lang.Package.getPackages()
for (p in packs)
print(packs[p]);