I have this Java class,
public class sample {
public Integer foo1(Integer x){
return x+5;
}
}
class SubClass extends sample{
public Integer foo2(Integer x){
return x+100;
}
}
And with Jython I want to call foo2
of the class SubClass
. I ended up with the following Python code,
import SubClass, sample
java_file = SubClass()
print java_file.foo2(3)
But running the Python code returns this error,
AttributeError: 'SubClass' object has no attribute 'foo2'
I also want to print the super class of a class and it's signature including the attributes like public, abstract, etc.
Is there a way to do this? Thanks!
You have to first create a instance... the invoke the method... like the following example:
Beach.java
public class Beach {
private String name;
private String city;
public Beach(String name, String city){
this.name = name;
this.city = city;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
Using Beach.java in Jython
>>> import Beach
>>> beach = Beach("Cocoa Beach","Cocoa Beach")
>>> beach.getName()
u'Cocoa Beach'
>>> print beach.getName()
Cocoa Beach
You can read more here
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments