This is the original method by passing in a DatabaseType.
trait DatabaseComponent
class Database {
this: DatabaseComponent =>
}
object Database {
def apply(dbType : DatabaseType): Unit ={
val database = dbType match {
case DatabaseType.H2 => new Database with H2Component {}
case DatabaseType.MySQL => new Database with MySQLComponent {}
case DatabaseType.PostgresSQL => new Database with PostgresSQLComponent {}
}
}
}
I want to, however, pass in the generic type and using typeOf(T)
like in C#
private void Apply<T>(){
switch(typeOf(T)){
Something
}
}
I am looking at this post How to match scala generic type?
But I am still not sure what this is doing.
1) Whats with the implicitly for this val string = implicitly[ClassTag[String]]
2) Why does T
have to be subclass of ClassTag
here implicitly[ClassTag[T]] match {
3) Should I be using ClassTag or TypeTag here?