You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: proposals/bound-callable-references.md
+15-5
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ Support "bound callable references" and "bound class literals".
19
19
- It's painful to write lambdas every time
20
20
- There's currently no way to reference an object member, which is sort of inconsistent with the fact that it's possible to reference static Java members
21
21
- It's present in Java and its absence in Kotlin is rather inconvenient
22
-
->42 votes on KT-6947: Callable reference with expression on the left hand side
22
+
->42 votes on [KT-6947](https://youtrack.jetbrains.com/issue/KT-6947): Callable reference with expression on the left hand side
23
23
24
24
## Description
25
25
@@ -102,10 +102,20 @@ Its `parameters` property doesn't have this parameter and the argument should no
102
102
103
103
## Open questions
104
104
105
-
- How to parse such expressions?
106
105
- API for "unbinding" a reference
107
-
- if unbound already, throw or return null, or provide both?
106
+
- Information about the original receiver type is absent in the type of a bound reference, so it's unclear what signature will the hypothetical "unbind" function have.
107
+
- One option would be an _unsafe_ "unbind" with a generic parameter which prepends that parameter to function type's parameter types:
108
+
109
+
```
110
+
class O {
111
+
fun foo() {}
112
+
val bound: () -> Unit = this::foo
113
+
val unbound: (O) -> Unit = this::foo.unbind<O>()
114
+
}
115
+
```
116
+
- If unbound already, throw or return null, or provide both?
108
117
- Should there be a way to obtain an unbound reference to an object member?
118
+
- May be covered with the general API for unbinding a reference, or may be approached in a completely different way (with a language feature, or a library function).
109
119
110
120
## Alternatives
111
121
@@ -121,7 +131,7 @@ We could try resolve type in LHS first, and only then try expression. This has t
121
131
-`::<member>`, `::class`.
122
132
For a class member, empty LHS of a callable reference may mean `this`.
123
133
Rationale: inside the class you can call `member()`, why not `::member` then?
124
-
-`super::<member>` (KT-11520)
125
-
- Support references to member extensions (KT-8835)
0 commit comments