Created
April 3, 2014 09:43
-
-
Save goldeneggg/9951560 to your computer and use it in GitHub Desktop.
scalaの可変長引数なメソッドをチェーン呼び出しした場合の挙動
This file contains 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
object Aho { | |
def main(args: Array[String]) { | |
aaa(1, "2", true) | |
ddd(1, "2", true) | |
} | |
// aaa - ccc, そのまま可変長引数を渡して実行 | |
def aaa(params: Any*) { | |
println("AAA params[%s] params class[%s]".format(params, params.getClass)) | |
bbb(params) | |
} | |
def bbb(params: Any*) { | |
println("BBB params[%s] params class[%s]".format(params, params.getClass)) | |
ccc(params) | |
} | |
def ccc(params: Any*) { | |
println("CCC params[%s] params class[%s]".format(params, params.getClass)) | |
} | |
// ddd - fff, ": _*" 付きで渡して実行 | |
def ddd(params: Any*) { | |
println("DDD params[%s] params class[%s]".format(params, params.getClass)) | |
eee(params: _*) | |
} | |
def eee(params: Any*) { | |
println("EEE params[%s] params class[%s]".format(params, params.getClass)) | |
fff(params: _*) | |
} | |
def fff(params: Any*) { | |
println("FFF params[%s] params class[%s]".format(params, params.getClass)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行結果。そのまま渡すとWrappedArrayによるラップがネストしていく
可変長引数は、その 関数内では宣言された型のArray になっている 為