views:

309

answers:

2

Hi,

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?

+3  A: 

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)
Filip Korling
I confirm (+1): see also http://smart2help.com/e-books/tip/#_Toc41169769
VonC
A: 

Thanks a bunch! It really helped me!

poulejapon