I found some snippets as follow:
import org.json4s.DefaultFormats
import org.json4s.jackson.JsonMethods._
import scala.io.Source
import scala.reflect.ClassTag
class ConfigLoader[C: ClassTag : Manifest](filePath: String) {
def loadFromFile(): C = {
implicit val formats = DefaultFormats
parse(Source.fromFile(filePath).mkString, false).extract[C]
}
}
What's the meaning of generic type like C: ClassTag : Manifest
?
The syntax
C: ClassTag
is a shorthand for(implicit ct: ClassTag[C])
.I.e. the full form of the class constructor is
In practical terms, it means that inside the definition of
ConfigLoader
, instances ofClassTag[C]
andManifest[C]
are required, and thus they have to be provided as arguments to the constructor.