简体   繁体   中英

Passing Class<?> parameter using Rhino

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.

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'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM