Skip to content

Instantly share code, notes, and snippets.

@fumokmm
Created July 14, 2012 15:03
Show Gist options
  • Save fumokmm/3111742 to your computer and use it in GitHub Desktop.
Save fumokmm/3111742 to your computer and use it in GitHub Desktop.
Groovyでクラスのフィールドアクセスいろいろ ref: http://qiita.com/items/d17efc6a70a0d9e2efbd
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