Inheriting methods from Java in PythonJavaClass
See original GitHub issueHow do I inherit fields and methods from a Java parent class into a PythonJavaClass?
Consider the following Java base class:
package org.jnius;
public abstract class AbstractParent {
int value=0;
protected AbstractParent(){}
public void doOne() { value = 1; }
public abstract void doTwo();
}
class TestAbstract(with_metaclass(MetaJavaClass, PythonJavaClass)):
__javaclass__ = 'org/jnius/AbstractParent'
__javainterfaces__ = []
@java_method('()Z')
def doTwo(self):
print("hello")
I can call doTwo(), but I cannot access doOne() from Python, nor value, i.e. neither of the following two statements work:
value = JavaField('()I;', static=False)
doOne = JavaMethod('()Z')
Moreover, we can’t mix Python classes that are children of PythonJavaClass and JavaClass.
It seems that PythonJavaClass (c.f. resolve_fields() in jnius_export_class.pxi) only examines self.__class__.__dict__
to find methods to add to the proxy class, while I could contend that, similar to autoclass()
, it should walk the interfaces and superclasses.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Inheritance - Learning the Java Language
A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are not inherited...
Read more >API — Pyjnius 1.0a1 documentation - Read the Docs
The idea is to subclass this JavaClass, add few JavaMethod , JavaStaticMethod , JavaField ... Decoration function to use with PythonJavaClass .
Read more >Inheritance in Java Example - DigitalOcean
Inheritance in Java is the method to create a hierarchy between classes by inheriting from other classes. Java Inheritance is transitive ...
Read more >Guide to Inheritance in Java - Baeldung
Simply put, in Java, a class can inherit another class and multiple interfaces, while an interface can inherit other interfaces.
Read more >Java Inheritance (Subclass and Superclass) - W3Schools
In Java, it is possible to inherit attributes and methods from one class to another. We group the "inheritance concept" into two categories:....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
i think that was solved by your doc update PR, closing, let me know if you feel more is needed.
@tshirtman android now provides for loading dex classes at runtime, which can be used to subclass java classes at runtime. beeware is pursuing this. ref: https://github.com/beeware/rubicon-java/issues/25#issuecomment-1165640203