Invalid static method resolution
See original GitHub issueI have a class hierarchy, where class Child
extends class Parent
, and they both define a method “newInstance”:
class Parent {
static
public Parent newInstance(){
return new Parent();
}
}
class Child extends Parent {
static
public Child newInstance(){
return new Child();
}
}
I’m trying to obtain a new Child
instance by invoking the static method Child#newInstance()
. However, I keep getting Parent
instances (instead of Child
instances), which indicates that PyJNIus has “redirected” my static method invocation to Parent#newInstance()
. This is obviously incorrect behaviour.
Using PyJNIus version 1.2.0.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Wrong static method resolution in Visual C++ - Stack Overflow
The compiler is clearly taking the wrong method as I have a dedicated variant for long long . What is the reason for...
Read more >Java Error: Non-static Variable/Method X Cannot be Referenced
Attempting to access a non-static variable/method from a static context without a class instance creates ambiguity.
Read more >Invalid static method call detected PHP-E1003 - DeepSource
The method you are trying to call is a private static method from a parent class. Bad practice. class Output { public static...
Read more >Can You Override Static Method in Java? Method ... - Java67
This means static methods are resolved even before objects are created, that's why it's not possible to override static methods in Java.
Read more >Static Keyword - Manual - PHP
Because static methods are callable without an instance of the object created, the pseudo-variable $this is not available inside methods declared as static....
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 Free
Top 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
From what i gather (didn’t look at this code in some time), we use Class.getMethods() to populate our list of methods, https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getMethods() and if we have multiple signatures for the same name, we use JavaMultipleMethod, and use
compute_score
at runtime to determine which method to call depending on various parameters, but… https://github.com/kivy/pyjnius/blob/5f6aa738b2b7ae496ec43bfadbf9933ee640bb7b/jnius/jnius_utils.pxi#L340-L352i think this should try to give less points the further in the class hierarchy of classes the method come from, because the previously mentioned
getMethods
method makes no promise on the order of the returned list, we might currently return any implementation, not necessarily the one the programmer expect.Thank you for confirmation, i’ll try adding the test case later, so we can avoid regressions 😃, then merge.