Jython and Java nested class

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?

Asked by: Arthur645 | Posted: 23-01-2022

Answer 1

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)

Answered by: Ada537 | Posted: 24-02-2022

Similar questions

java - Is there a good NumPy clone for Jython?

Closed. This question does not meet Stack Overflow guid...

java - What is Jython and is it useful at all?

Closed. This question is opinion-based. It is not c...

java - Send Raw hex data in jython udp packet

I'm experience with Java, but I have to integrate a java library into a co-workers python code. Enter jython, yay! We are trying to send a UDP packet with a very specific data section. We are building up the packet like so: version = 0x0001 referenceNumber = 0x2323 bookID = byteArray('df82818293819dbafde818ef') For easy of explanation assume byteArray takes in a string of h...

java - use .pyc files via Jython

I am working on building a web interface for a Python tool. It's being designed using J2EE (Spring). In the process, I need to make calls to Python functions and hence I am using Jython for the same. But for some modules I don't have the Python source files, I only have the .pyc files, and a document listing the methods of that file. I need to know how I can call these functions inside the

java - Jython, where should i put my .py files

I am really new to Java/Eclipse and I am trying to do this Jython tutorial. I do not understand where I should put my python files the IDE's tree directory structure. I've tried placing the file in several locations without success (I must be missing something). This is the error message I get: <mod...

Jython, use only a method from Python from Java?

When reading and using this article it assumes that we have a full object definition with class and mapping (proxy) objects from python to java. Is it possible to only import a method (not defined inside a class, but using internal python class) from a piece of code in python without wrapping it in a class ...

java - jython Can't list error

I am trying to convert a python class into Java byte code with Jython (on mac osx lion) ./jython -m compileall /Users/owengerig/Downloads/Code\ Downloads/cryptPYTHON.py but get this error, which gives no indication of whats wrong Listing /Users/owengerig/Downloads/Code Downloads/cryptPYTHON.py ... Can't list /Users/owengerig/Downloads/Code Downloads/cr...

Run Jython code from java class

I am working on executable jar file that will run jython file to get some result. I tried calling jython file through this technique. Run .bat file from java class and that .bat file will call Jython file. Runtime rt = Runtime.getRuntime(); Process process = rt.exec(new String[] { "cmd.exe", "/c", "D:\\calljython.bat " + parameters + "" }); Af...

java - Send mail with mapi in jython

I am trying to use pywin in a jython application for sending emails w/ attachments with outlook. Pywin needs a win32 enviroment, but since we are in java and the function sys.platform returns "java1.6", everything does not work properly. Should I use JMapi instead of pywin? If the answer is positive, where could I find some examples? Thank you. so...

java - Jython no module named random

I'm working on a server that is made off of Java. At certain points of time (ie someone clicks on a object in the game for example), the server will load a script made using Jython. I'm having trouble getting the script to work, mainly because one imports the module random. Here is the script: from resources.common import RadialOptions import sys import random def createRadial(core, owner, target, radials...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)