调用类镜像为我提供了传递名称和年龄的默认构造函数,但是推断出的构造函数太正确了,在这里我可以创建一个具有默认值的人,并允许我根据需要设置它们.
Invoking class mirror gives me the default constructor of passing name and age but there are inferred constructor too right where i can create a person with default values and allow me to set them as needed.
如何在方法镜像中调用它.在这种情况下,我期望有4个构造函数,分别具有两个值和2个独立字段,以及1个没有字段.
How do you invoke that in method mirror. I'm expecting 4 constructors in this case 1 with both values and 2 for individual fields and 1 with no fields.
我选择此作为示例VO,因此请不要对设计发表评论.问题是如何推断默认值的构造函数
I choose this as an example VO so please don't comment on the design. The question is on how to infer the constructors with default values
推荐答案只有一个构造函数.默认值保留在人"随行对象中.呼叫 new Person(年龄= 10)会变成类似 new Person(Person.< init> $ default $ 1(),10).
There is only one constructor. The default values are kept in the Person companion object. A call new Person(age = 10) is turned into something like new Person(Person.<init>$default$1(), 10).
更多推荐
如果我们在构造函数中定义了默认值,如何使用Scala反射调用默认构造函数
发布评论