Reputation: 81
Stumbled these two lines of code while reading through akka-actor source:
abstract class ExtensionKey[T <: Extension](implicit m: ClassTag[T]) extends ExtensionId[T] with ExtensionIdProvider {
def this(clazz: Class[T]) = this()(ClassTag(clazz))
At the bottom of this file:
https://github.com/akka/akka/blob/master/akka-actor/src/main/scala/akka/actor/Extension.scala
I cannot wrap my head around the constructor call "this()". No where a constructor is defined without parameters? How does this work? Read a few articles about scala constructor overloads and still can't explain it.
Upvotes: 1
Views: 58
Reputation: 170713
The primary constructor ExtensionKey[T <: Extension](implicit m: ClassTag[T])
actually has two parameter lists: the first one, for non-implicit parameters, is empty. I.e. this is exactly the same as if they wrote ExtensionKey[T <: Extension]()(implicit m: ClassTag[T])
.
Upvotes: 2