Comments (7)
Is overriding java method using python code possible for now?
What about java class inheritance?
from pyjnius.
that was ~4 years ago, and to my knowledge no, generating java bytecode at runtime still looks like the only option (and maybe it's not as bad as i though and we should look into that).
from pyjnius.
One workaround is:
- create separate Java project including the android.jar of the targeted android version API
- implement the code (inheritance/overrides...)
- export to jar
- import in buildozer
to use it with autoclass
from pyjnius.
Sorry for the delay, can you provide more specific (testcases?) description for each of those issues? I started some work to allow inheritance of java classes from python (using proxies), but it's not complete, however, the issues you point here seems loosely related to that, and should probably be splitted in several different issues.
from pyjnius.
Sorry to come into the discussion, but inheriting Java a class might not be what you need @apalala, I think that it's a better idea to wrap the Java class in a Python class like it's done in this class. It might not be obvious in the linked code because all the autoclass are done in java.py but the code is equivalent to
class MyJavaWrapperClass(AnyPythonClassOrMixin):
def __init__(self, *args, **kwargs):
JavaClass = autoclass('org.uber.cool.JavaClass`)
self._my_java_object = JavaClass(*args, **kwargs) # use double underscore to "hide" the Java object
The reasons not to inherit the Java class are:
- Java methods use Java naming conventions and looks ugly in Python code, you will most likely want to rename the methods so that they have a Python look and don't surprise other developers used to the pep8 (except if you do old twisted and old Zope code...)
- Generally, it avoids cluttering the python object dict with Java inherited methods, some Java methods have nothing nothing to do in Python bindings, they will barely be called maybe never. Wrapping the Java class make the Python class cleaner in REPL and possibly avoids dreadful calls to unsupported Java methods. Mind the fact that If you don't use the double underscore, Java methods are still easily available.
- Last but not least, there are high chances that you will have to add boilerplate code before or after the call to some Java methods, you will most likely override some Java methods in Python so that you do the proper type/class conversion or other stuff, so you end up creating a Python method for the Java method just like you would do when you wrap the Java class instead of inheriting it while still being able to A) rename the method B) keep the dict clean. Look at the methods of
class Element
,class Node
andclass Relationship
in graph almost all of them has boilerplate code even if most of the time it is to make the API more Pythonic ;)
From a performance perceptive, I don't think there is any impact but @tshirtman might know better.
Another thing, wrapping Java objects works right now and really well :-)
from pyjnius.
I've spent quite a lot of time looking in this, and i had come to the conclusion that there was no practical way of doing so, short of generating java bytecode at runtime, there are libraries to do that, but that felt like adding a lot of complication to the library, and probably out of scope. Not sure about closing, but i don't think it's going to get worked on, so it wouldn't be unreasonable to mark it as wontfix.
from pyjnius.
@monami7001 any progress?
from pyjnius.
Related Issues (20)
- pyjnius build error on s390x HOT 10
- ClassNotFoundException for android.media.midi.MidiManager.OnDeviceOpenedListener HOT 3
- unexpected error for jdk17 HOT 4
- Crashes on Apple M1 HOT 27
- How to add everything under M2 repository to pyjnius classpath? HOT 2
- DeprecationWarning: pkg_resources is deprecated as an API
- pyjnius build error, still coming HOT 10
- Including a JAR on Android HOT 2
- Support mail address is broken HOT 2
- OverflowError: value too large to convert to jshort HOT 4
- How to create Webview with FileChooser HOT 1
- Moderinze `java` code? HOT 2
- installation documentation could be refreshed HOT 3
- Usage without JDK HOT 6
- AttributeError: 'Class' object has no attribute '_JavaClass__cls_storage' HOT 4
- Running python script on Android but in Docker container HOT 1
- Getting a pointer to JavaVM
- Dependency Dashboard
- No jvm.dll found HOT 3
- Unrecognized option: --add-exports / --add-opens HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyjnius.