Data Class Supertype and Primary Constructor

Is there a way to restrict a type parameter to be a data class, à la Product for Scala case classes? I think the Any in the construction, below, is redundant.

fun <T: Any> foo(...)

Also, given a KClass, is there a way to figure out which constructor is the primary constructor (at least for a data class)? Perhaps it’s always the first one listed.

val ctor: Constructor<T> = kClass.constructors.first().javaConstructor!!
1 Like

Any is not redundant, it limits T to non-null types.

Errr… kClass.primaryConstructor? :slight_smile:

2 Likes

First of all, that’s a very good point.

Secondly, d’oh! That was thick of me. : / I was looking at the java ctors.

Thanks, again.