is it possible to reference an object's member as ...
# announcements
is it possible to reference an object's member as a kproperty1? rn if i reference a object's member i get a KProperty0 but for my use case it'd be nice if I could use a KProperty1 so i can bound the receiver.
If you get a reference to a property on a class or interface, it will be a KProperty1; on an object it will be a KProperty0. So in this case, you probably want to replace the object in the reference with the class/interface specifying the property
Does you mean an
or an instance of a
? If you mean the former ... then it's not really possible (at least conceptually speaking).
thanks for responding. lets go with this function
Copy code
fun <T> Foo<T>.values(vararg values: KProperty1<T, *>) { ... }
In the Foo class it has an instance of T, and could get the values of the kproperties. With this method I know the values are from T and I'm happy with this. However if I use a KProperty0<*> e.g., from an object, I lose the guarantee that the property is from T.
Hmm, alright, that's unfortunate. Didn't really think it would be possible, but wasn't complete sure. thanks for the clarification
Oh, I'm guessing you have
object UnknownName : T { ... }
You'll need an interface or similar as Steve has suggested.
heres a barebones snippet
Copy code
class SelectOp<D>(val entity: Entity<D>): Operation

class SelectValuesOp<D>(val entity: Entity<D>, val values: List<Column<*>>): Operation

fun <D> SelectOp<D>.values(vararg values: KProperty1<Entity<D>, Column<*>>) {

//user code
object SomeEntity: Entity<SomeEntityData>() {
  val foo = Column<Int>()

data class SomeEntityData(val foo: Int)
in this situation, id like the user to be able to do
Copy code
how would i go about using an interface/class to specify properties that are specified by the user?