scala - get class from a string

前端 未结 1 368
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-04 12:26

From Scala, I\'m using a Java library that expects a class argument. Example:

def service: OAuthService  = new ServiceBuilder()
                                     


        
1条回答
  •  不知归路
    2021-01-04 13:11

    Use forName method:

    scala> Class.forName("scala.collection.mutable.ArrayBuffer")
    res0: java.lang.Class[_] = class scala.collection.mutable.ArrayBuffer
    

    0 讨论(0)
提交回复
热议问题