lundi 30 octobre 2017

How can I add a class to Scala Set

I would like to passing a parameter via String and construct a Set of class objects, like this:

def getTypes(value: String) : Set[Class[Base]] = {
  var set = Set[Class[Base]]()
  var input = value.split(",")
  if(input.contains("XXX"))
    set ++ Class[xxx]
  if(input.contains("YYY"))
    set ++ Class[yyy]
  if(input.contains("ZZZ"))
    set ++ Class[zzz]
  set
}

Then looping the set and use class.newInstance() to create the actual object to do something later. The able code can compile, but when it run, it complaint that

Error:(32, 16) object java.lang.Class is not a value
    set ++ Class[xxx]

Any clue about about that?





Aucun commentaire:

Enregistrer un commentaire