我声明了一个 Java 类 -
class Beach {
private String name, city;
public Beach(String name, String city) {
this.name = name;
this.city = city;
}
}
我将它导入 jython 并尝试创建一个对象 -
import Beach
b = Beach("candolim", "goa")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: java.lang.Object(): expected 0 args; got 2
我的两个参数构造函数在哪里?
编辑:
我遵循这些确切的步骤 -
// Comment - Remove all files from directory to not create any confusion.
$ rm -rf *
$ vi Beach.java
class Beach {
private String name, city;
public Beach(String name, String city) {
this.name = name;
this.city = city;
}
}
$ javac *.java
$ javap Beach
Compiled from "Beach.java"
class Beach {
public Beach(java.lang.String, java.lang.String);
}
$ jython
>>> import Beach
>>> b = Beach()
>>> dir(b)
['__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__subclasshook__', '__unicode__', 'class', 'equals', 'getClass', 'hashCode', 'notify', 'notifyAll', 'toString', 'wait']