Created
July 14, 2012 15:03
-
-
Save fumokmm/3111742 to your computer and use it in GitHub Desktop.
Groovyでクラスのフィールドアクセスいろいろ ref: http://qiita.com/items/d17efc6a70a0d9e2efbd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A { | |
def foo | |
} | |
def a = new A(foo: 'Foo') | |
assert a.foo == 'Foo' // プロパティアクセス(暗黙的) | |
assert a.getFoo() == 'Foo' // プロパティアクセス(明示的) | |
assert a.foo == 'Foo' // フィールドアクセス | |
assert a['foo'] == 'Foo' // マップアクセス | |
assert a.getAt('foo') == 'Foo' // マップアクセス(メソッド) | |
assert a.'foo' == 'Foo' // プロパティアクセス(文字列) | |
assert a."f${'o'*2}" == 'Foo' // プロパティアクセス(GString) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment