Prechádzať zdrojové kódy

[jvm[ add java.util.function.Function as implicit interface

see #9576
Simon Krajewski 5 rokov pred
rodič
commit
094e645036

+ 8 - 1
src/generators/jvm/jvmFunctions.ml

@@ -307,7 +307,14 @@ module JavaFunctionalInterfaces = struct
 				jpath = juf,"BiConsumer";
 				jname = "accept";
 				jparams = ["T";"U"]
-			}
+			};
+			{
+				jargs = [tp "T"];
+				jret = Some (tp "R");
+				jpath = juf,"Function";
+				jname = "apply";
+				jparams = ["T";"R"]
+			};
 		]
 
 	let unify jfi args ret =

+ 13 - 0
tests/unit/src/unit/issues/Issue9576.hx

@@ -0,0 +1,13 @@
+package unit.issues;
+
+class Issue9576 extends Test {
+	#if jvm
+	function test() {
+		eq(6, foo(cast i -> i * 2));
+	}
+
+	function foo(f:java.util.function.Function<Int, Int>) {
+		return f.apply(3);
+	}
+	#end
+}