@@ -79,7 +79,10 @@ classes.
79
79
80
80
## What does "signature polymorphism" mean, exactly?
81
81
82
- As the [ Javadoc for ` MethodHandle ` ] ( https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/invoke/MethodHandle.html ) says,
82
+ There is a formal description in [ JLS 15.12.3] ( ) , but a more readable
83
+ version is in the [ Javadoc for
84
+ ` MethodHandle ` ] ( https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/invoke/MethodHandle.html ) .
85
+ It says:
83
86
84
87
> A signature polymorphic method is one which can operate with any of
85
88
> a wide range of call signatures and return types.
@@ -106,6 +109,8 @@ type parameters.
106
109
107
110
The following example should help make all of this clearer.
108
111
112
+ * [ JLS 15.12.3 ] : https://docs.oracle.com/javase/specs/jls/se17/html/jls-15.html#jls-15.12.3
113
+
109
114
## How do I call a signature polymorphic method from Scala?
110
115
111
116
Take ` MethodHandle ` for example. It provides an ` invokeExact `
@@ -189,9 +194,9 @@ request](https://github.com/lampepfl/dotty/pull/16225).
189
194
190
195
### The path not taken
191
196
192
- Along the way we explored an alternative approach, suggested by Jason
193
- Zaugg, which involved rewriting each call site to include a
194
- cast to a structural type containing an appropriately typed method.
197
+ Along the way we explored an alternative approach, suggested by Jason,
198
+ which involved rewriting each call site to include a cast to a
199
+ structural type containing an appropriately typed method.
195
200
196
201
In that version, the ` replace ` call-site in the example above was
197
202
rewritten from:
@@ -226,17 +231,3 @@ complicated the implementation.
226
231
These are welcome on the Scala Contributors forum thread at:
227
232
228
233
* (TODO Discourse link, with link back to this post)
229
-
230
- > TODO: include a link to the relevant section of the JLS
231
-
232
- > TODO: find the JEP and any design discussions;
233
- > VarHandle JEP https://openjdk.org/jeps/193
234
- > hmm wait, did MethodHandle actually land in JDK 7?
235
- > yes! https://docs.oracle.com/javase/7/docs/api/java/lang/invoke/MethodHandle.html
236
- > references signature polymorphism
237
-
238
- > TODO: link to something that explains what Java reflection even is?
239
-
240
- > TODO:
241
- > cover the type ascription vs cast design issue?
242
- > (Java has casts, in Scala type ascription is more idiomatic)?
0 commit comments