Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.
This repository was archived by the owner on Aug 5, 2021. It is now read-only.

Subclassing/Inheriting Java classes? #164

Open

Description

@csachs

I'd like to subclass / inherit Java types from within Python, however this seems not to work:
Example:

import jpyutil
jpyutil.init_jvm()
import jpy

BigInteger = jpy.get_type("java.math.BigInteger")

print(BigInteger("1"))  # works

class MyBigInteger(BigInteger):
    def additionalMethod(self):
        print("...")

print(MyBigInteger("1")) # does not work

Yields

RuntimeError: no constructor found (missing JType attribute '__jinit__')

(Any relation to #155 ?)

Am I doing something wrong? Is there any easy work-around for the situation? (Theoretically one proxy all calls etc., but I'd prefer if Python's OOP would remain intact)
(Actually, I'd like to override certain Java-land methods and feed the subclassed object back to the Java-land, to be able to easily call them by the parent object's definition …)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions