English 中文(简体)
在使用地图构造时,在野心中触发的定型号
原标题:In what order are setters triggered in groovy when using map constructor

在格罗维耶,当我称之为地图构造者时,例如,

new Player(name: Lionel , surname: Messi , number: 10, team:barcelona)

我如何知道把财产设定者称为谁?

我需要知道这一点,因为我需要在我的一些组别中适用某种逻辑,我需要知道,在每一组别被点名时,会把哪些数据放在标的上。

最佳回答

采用快速文字,似乎按通过顺序确定:

class Foo {
    def settersCalled = []
    def setFoo(foo) { settersCalled <<  foo  }
    def setBar(bar) { settersCalled <<  bar  }
    def setBaz(baz) { settersCalled <<  baz  }
}

assert new Foo(foo: 0, bar: 0, baz: 0).settersCalled == [ foo ,  bar ,  baz ]
assert new Foo(bar: 0, foo: 0, baz: 0).settersCalled == [ bar ,  foo ,  baz ]
assert new Foo(baz: 0, bar: 0, foo: 0).settersCalled == [ baz ,  bar ,  foo ]

然而,你可以更多地了解格罗莫夫以夸张的方式遵循该守则。 如果你在该法典的一个编组中设置一个空白点,你就会注意到,打字机包括,这意味着这些特性正在由这种方法确定。 如果我们看一下>>>>>> 准则> 我们可以确认,它正在利用地图探测器来推翻施工者通过地图。 而且,由于Groovy利用下令实施的连接HashMaps,作为未完成的地图执行,我们可以得出结论,这些特性将按构造者地图界定的顺序排列:

问题回答

暂无回答




相关问题
UserControl constructor with parameters in C#

Call me crazy, but I m the type of guy that likes constructors with parameters (if needed), as opposed to a constructor with no parameters followed by setting properties. My thought process: if the ...

Strange "type class::method() : stuff " syntax C++

While reading some stuff on the pImpl idiom I found something like this: MyClass::MyClass() : pimpl_( new MyClassImp() ) First: What does it mean? Second: What is the syntax? Sorry for being such ...

Anonymous class question

I ve a little doubt over this line: An anonymous class cannot define a constructor then, why we can also define an Anonymous class with the following syntax: new class-name ( [ argument-list ] ) {...

Why copy constructor is not called in this case?

Here is the little code snippet: class A { public: A(int value) : value_(value) { cout <<"Regular constructor" <<endl; } A(const A& other) : value_(other....

Invoking an instance method without invoking constructor

Let s say I have the following class which I am not allowed to change: public class C { public C() { CreateSideEffects(); } public void M() { DoSomethingUseful(); } } and I have to call M ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

热门标签