我有这个Java类,
public class sample {
public Integer foo1(Integer x){
return x+5;
}
}
class SubClass extends sample{
public Integer foo2(Integer x){
return x+100;
}
}
使用Jython我想调用类foo2
的{{1}}。我最终得到了以下Python代码,
SubClass
但是运行Python代码会返回此错误,
import SubClass, sample
java_file = SubClass()
print java_file.foo2(3)
我还想打印一个类的超类及其签名,包括public,abstract等属性。
有办法做到这一点吗?谢谢!
答案 0 :(得分:1)
您必须首先创建一个实例...调用方法...如下例所示:
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
您可以阅读更多here