Question

I'm using Jython to write tests for a Java project. It works well, but I can't figure how to get access to a java public nested class.

package mypackage;

public class NyClass {
    public class MyNestedClass {
         ...
    }
}

Does somebody knows how to do this?

Was it helpful?

Solution

I'm not entirely sure by what you mean by access, but if you after creating instances of the MyNestedClass it's no problem in jython.

In this case, since MyNestedClass is a non-static nested class every instance of it needs a reference to an instance of MyClass. To do this in jython:

import mypackage.MyClass
import mypackage.MyClass.MyNestedClass

outer = mypackage.MyClass()
inner = mypackage.MyClass.MyNestedClass(outer)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top