Currently, I am facing a challenge while trying to integrate a scripting endpoint into our application. The issue at hand is as follows: Is it viable to create an object that is an instance of an abstract class with implemented methods? In the context of Java, the scenario would resemble the following:
SimpleObject obj = new SimpleObject("constructor arg0") {
public void doCustomAction() {
System.out.println("Action");
}
}
In this case, SimpleObject
is an abstract class containing an abstract method called doCustomAction
.
How can one achieve such behavior using a Java Scripting Engine? My attempt involves the following approach:
obj1 = new SimpleObject("value1") {
doCustomAction : function() {
//Perform actions.
}
}
Unfortunately, an exception is thrown by the engine:
javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException:
error instantiating (JavaAdapter: first arg should be interface Class (<Unknown source>#1)):
class SimpleObject is interface or abstract (<Unknown source>#1) in <Unknown source> at line number 1