Out-projected type 'KProperty1<out Any, Any?>' prohibits the use of 'public abstract fun get(receiver: T): R defined in kotlin.reflect.KProperty1'
Inspired by @Alexey.Belkov’s suggestions above, I tried casting the class at the start of the expression:
val nonNullPropertyNames = (obj::class as KClass<Any>).memberProperties
.filterNot { it.get(obj) == null }.map { it.name }
And now it works!
I get a warning about Unchecked cast: KClass<out Any> to KClass<Any>, however in this situation I know it is safe because the obj I pass into get() is the same as the one that I got the KClass from. If that weren’t the case (i.e. you can’t guarantee that the property came from the exact same KClass as the object you’re passing in), then making this cast could cause runtime errors as you might call get() with an object that doesn’t actually have the property.
If you’re using this::class you will get this as well. In case you know what this is (i. e. a class where you’re currently writing a regular function in) you can just specify the class name explicitly: Foo::class. That gives the compiler the necessary hint.