我正在尝试调用自定义集合对象的构造函数。该自定义对象接受 Class 类型的参数。
在java中,这是这样完成的:
ICollection col = new PersistentCollection(ContentX.class);
这是我第一次深入rhino,我还没有弄清楚如何传递这个参数。我发现“class”是一个保留词,因此不可用。
我想我可以像这样从 Class.forName 获取类:
importPackage(Packages.something.collections);
importPackage(Packages.something.content4);
var col = new PersistentCollection(Class.forName(ContentX));
但它只是抛出 ClassNotFoundException - 带有完全限定的路径 some.content4.ContentX!很明显它找到了这个类,否则它不会知道它的路径。
我做错了吗?遗憾的是,我现在无法更改 java 库,我需要在不进行新部署的情况下修复数据。
谷歌搜索 javascript 类只会产生 DOM/CSS 问题。
I am trying to call a constructor for a custom collection object. This custom object takes in a parameter of type Class.
In java, this is done like this:
ICollection col = new PersistentCollection(ContentX.class);
This is my first dive into rhino, and I haven't been able to figure out quite how to pass this parameter. I figured out that "class" is a reserved word and therefor not usable.
I figured that I could get the Class from Class.forName like this:
importPackage(Packages.something.collections);
importPackage(Packages.something.content4);
var col = new PersistentCollection(Class.forName(ContentX));
But it just tosses ClassNotFoundException - with the fully qualified path something.content4.ContentX! So obviously it found the class or it wouldn't have known the path to it.
Am I doing it wrong? Sadly, I'm not in any position to change the java library right now, I need to fix the data without a new deploy.
Googling for javascript class just yields DOM/CSS problems.
发布评论
评论(1)
我认为你只需要这样做:
或者,如果你的类名是一个字符串:
I think you simply need to do:
Or, if your class name is a string: