# Is there a way to get from KProperty0 to KProperty1?

**URL:** <https://discuss.kotlinlang.org/t/is-there-a-way-to-get-from-kproperty0-to-kproperty1/25933>\
**Category:** Libraries\
**Created:** [November 8, 2022, 9:05am UTC](https://discuss.kotlinlang.org/t/is-there-a-way-to-get-from-kproperty0-to-kproperty1/25933 "2022-11-08T09:05:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![knolle](https://avatars.discourse-cdn.com/v4/letter/k/a9adbd/32.png) [@knolle](https://discuss.kotlinlang.org/u/knolle)\
**Post date:** [November 8, 2022, 9:05am UTC](https://discuss.kotlinlang.org/t/is-there-a-way-to-get-from-kproperty0-to-kproperty1/25933/1 "2022-11-08T09:05:17Z")

</div>

I cannot find a way to get from an instance-bound property to the respective class property, e.g. from `::myVal` to `MyClass::myVal`.  
I feel, that this should be possible since `::myVal` is just a specialized case of `MyClass::myVal`.  
Do I miss something?

---

<div class="post-metadata">

**Author:** ![tlin47](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@tlin47](https://discuss.kotlinlang.org/u/tlin47)\
**Post date:** [November 8, 2022, 8:18pm UTC](https://discuss.kotlinlang.org/t/is-there-a-way-to-get-from-kproperty0-to-kproperty1/25933/2 "2022-11-08T20:18:48Z")

</div>

I am not an expert on Kotlin reflection.

But usually, it is very easy to get from a general case to a specialized case, but not easy to get from a specialized case to the general case.

If you have the means to determine the age of any person, it will be easy to determine the age of your uncle Herbert. But in the opposite direction, it is not true: Just knowing how to determine the age of your uncle Herbert does not give you the ability to determine everyone’s ages.

Your case has the same problem: `KProperty0` may be the property of one specific object (this = “Uncle Herbert”), but it does not automatically contain a way to get this property of any other object of the same type.

The doc of `KProperty0` even states that it _can_ be a property that has its receiver bound to it (“Uncle Herbert”), but it _can_ also be a property that is defined in a _receiverless_ context. So, it is even possible that it is not “an int that is bound to some fixed object” - it could even be “just an int”. Therefore, in this case it is impossible to get a (meaningful) general case back from it.

---

<div class="post-metadata">

**Author:** ![knolle](https://avatars.discourse-cdn.com/v4/letter/k/a9adbd/32.png) [@knolle](https://discuss.kotlinlang.org/u/knolle)\
**Post date:** [November 9, 2022, 8:17am UTC](https://discuss.kotlinlang.org/t/is-there-a-way-to-get-from-kproperty0-to-kproperty1/25933/3 "2022-11-09T08:17:16Z")

</div>

Ah, yes, you are of course right regarding the general situation. A `KProperty0` might be something different from a member value, I didn’t think about it.  
What I thought was, that `::myProp` could (under the hood) be something like a `KInstanceProperty` which still knows its bound object instance. In this case it would be possible to go from instance to class and thus to the respective `MyClass::myProp` reference.  
But as `::myProp` just ends up being an ordinary `KProperty0`, the instance information is lost (or hidden).

So I fear there is no solution for my request, unless they introduce a special member property type.
