3

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?

1 Answer 1

4

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.