当前位置: 动力学知识库 > 问答 > 编程问答 >

Scala : Class as a Parameter

问题描述:

I want to pass a class as a parameter to my function in Scala.

e. g. def getIndexes(...): Iterator

this is like the structure of function

I want to pass something like Vertex.class or say Edge.class as my parameter.

网友答案:

If your are not after a type parameter to the method as per Gabriele's answer, but actually want to pass a Class object as a parameter, the type of the class object in Scala is parametric, so to accept any class you would do:

def myMethod(aClass: Class[_])
网友答案:

Would passing a type parameter work for you?

def getIndexes[T]()
分享给朋友:
您可能感兴趣的文章:
随机阅读: