通过课程使用Rhino的参数

发布于 2024-09-27 21:47:42 字数 628 浏览 6 评论 0 原文

我正在尝试调用自定义集合对象的构造函数。该自定义对象接受 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三生殊途 2024-10-04 21:47:42

我认为你只需要这样做:

var col = new PersistentCollection(ContentX);

或者,如果你的类名是一个字符串:

var col = new PersistentCollection(
        java.lang.Class.forName('something.content4.ContentX'));

I think you simply need to do:

var col = new PersistentCollection(ContentX);

Or, if your class name is a string:

var col = new PersistentCollection(
        java.lang.Class.forName('something.content4.ContentX'));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文