Skip to content

Instantly share code, notes, and snippets.

@fumokmm
Created May 9, 2012 22:13
Show Gist options
  • Select an option

  • Save fumokmm/2649307 to your computer and use it in GitHub Desktop.

Select an option

Save fumokmm/2649307 to your computer and use it in GitHub Desktop.
Groovyでメソッド呼び出しのサンプル
def method(Map map) {
println 'signatures <map>'
println "$map"
}
def method(Map map, String str) {
println 'signatures <map, String>'
println "$map, $str"
}
def method(Map map, String str1, String str2) {
println 'signatures <map, String, String>'
println "$map, $str1, $str2"
}
def method(Map map, String str1, String str2, String str3) {
println 'signatures <map, String, String, String>'
println "$map, $str1, $str2, $str3"
}
def method(Map map, String... strList) {
println 'signatures <map, String...>'
println "$map, $strList"
}
def line = { def _30 = '-'*30; println "$_30 $it $_30" }
line(1)
method(key1: 'value1')
line(3)
method(key1: 'value1', key2: 'value2')
line(3)
method(key1: 'value1', key2: 'value2', 'str1')
line(4)
method(key1: 'value1', key2: 'value2', 'str1', 'str2')
line(5)
method(key1: 'value1', key2: 'value2', 'str1', 'str2', 'str3')
line(6)
method(key1: 'value1', key2: 'value2', 'str1', 'str2', 'str3', 'str4')
// ↓これはエラー
//method('そして文字列', ’文字列2', [str: 'str1', str2: 'str2'])
//**参考
//[http://groovy.codehaus.org/Extended+Guide+to+Method+Signatures:title:bookmark]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment