我正在试验Kotlin中的反射功能,但我似乎不知道如何获得KType值.
Suppose I have a class that maps phrases to object factories. In case of ambiguity, the user can supply a type
parameter that narrows the search to only factories that return that type of object (or some sub-type).
fun mapToFactory(phrase: Phrase,
type: KType = Any::class): Any {...}
type
needs to accept just about anything, including Int
, which from my experience seems to be treated somewhat specially. By default, it should be something like Any
, which means "do not exclude any factories".
如何将默认值(或任何值)指定给type
?