vendredi 17 mars 2017

What to assign to a KType in Kotlin?

I'm experimenting with the reflection functionality in Kotlin, but I can't seem to understand how to obtain a KType value.

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".

How do I assign a default value (or any value) to type?





Aucun commentaire:

Enregistrer un commentaire