scala - Passing Type Constructor to Var Args of `Any` Type -
given:
scala> def f(x: any*): string = "foo" f: (x: any*)string my understanding it'll take 1 or more arguments of any, , return "foo".
scala> f(1, 2, list(4), "foo") res5: string = foo scala> f(null) res6: string = foo but, passed in higher-kinded type:
scala> f(option) res7: string = foo ... expected compile-time failure since edit - think it's type constructor.
why did f(option) work, i.e. output "foo"?
that not type constructor, , there's nothing special var args in case. companion object of option. if make f generic on type parameter a, can see option.type (the type of options companion object) inferred.
scala> def f[a](a: a) = f: [a](a: a)a scala> f(option) res1: option.type = scala.option$@59f95c5d
Comments
Post a Comment