Jython and Java nested class

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

package mypackage;

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

Does anyone know how to do this?

+3
source share
1 answer

I am not quite sure what you mean by access, but if you are after creating instances of MyNestedClass this is not a problem in jython.

In this case, since MyNestedClass is a non-static nested class, each instance of it requires 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)
+4
source

Source: https://habr.com/ru/post/1698962/


All Articles