Greetings Janino Community,
I am bumping into a problem with janino when using covariant return types. I am trying to generate a class which implements interfaces which themselves declare methods with covariant return types. Something like:
public static interface Foo
{
public Number getFoo();
}
public static interface Bar extends Foo
{
public Integer getFoo();
}
If, I generate a class like this:
public static void main(String[]args) throws Exception
{
String code = "public Integer getFoo(){return 1;} ";
ClassBodyEvaluator cbe = new ClassBodyEvaluator();
cbe.setParentClassLoader(GeneratedObjectFactory.class.getClassLoader());
cbe.setImplementedTypes(new Class[]{Bar.class});
cbe.setClassName("BarImpl");
cbe.cook(code);
System.out.println("Compiled");
Foo thingie = (Foo) cbe.getClazz().newInstance();
Number b = thingie.getFoo();
System.out.println("Should be 1: " + b);
}
I get the exception: Line 1, Column 1: Non-abstract class "Bar" must implement method "java.lang.Number com.subx.general.core.iapi.factory.GeneratedObjectFactory$Foo.getFoo()"
Interestingly enough, if I replace the code string with this: "public Integer getFoo(){return 1;} public Number getFoo() {return 1;}". Janino compiles and java executes this just fine.
What I'm wondering is: Is it a reasonable practice to manually generate the covariant method versions for Janino?
Also, I noticed that the front page of supported features vs. unsupported features does not mention covariant return types (or did I miss it)?
Thanks for a great tool! Janino ROCKS!
Cheers,
--
-pete
peter m. murray
pete@...