public constructor_name() { this(param) } public constructor_name(int param) { this.param = param }
在Java中,我们有这种自引用构造函数吗?
class A def initialize(one) puts "constructor called with one argument" end def initialize(one,two) puts "constructor called with two arguments" end end
您可能希望有2个具有不同参数的构造函数.但是,评估的最后一个将是类的构造函数.在这种情况下初始化(一,二).