scala - When do you have to include the abstract type parameter? -
here's 2 piece of example code, found here:
scala> val im = m.reflect(new c) im: reflect.runtime.universe.instancemirror = instance mirror c@3442299e and here:
scala> def mkarray[t : classtag](elems: t*) = array[t](elems: _*) the first piece of code uses method defined in scala.reflect.api.mirrors (found here):
abstract def reflect[t](obj: t)(implicit arg0: classtag[t]): universe.instancemirror if notice, there's classtag used classtag[t] , 1 used classtag. what's reason difference?
for part, both equivalent.
foo[t: classtag]() is syntactic sugar for
foo[t]()(implicit ct: classtag[t] however, difference between these signatures in former, have access classtag via implicitly[classtag[t]] while in latter, can use ct
syntax change note: before 2.10.x used not possible have have both context bound classtag , implicit argument list, such as:
foo[t: classtag]()(implicit ex: executioncontext) the error used reported "error: cannot have both implicit parameters , context bounds". intellij 13 still reporting late 2.10.4, accepted scala compiler.
Comments
Post a Comment