-
-
Notifications
You must be signed in to change notification settings - Fork 662
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Functional interface support (#11019)
* [jvm] deal with functional interfaces see #9576 * [typer] handle functional interface assignments * Added tests for Java functional interfaces. * fix test --------- Co-authored-by: EliteMasterEric <ericmyllyoja@gmail.com>
- Loading branch information
1 parent
9717436
commit f132e61
Showing
11 changed files
with
174 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
interface MathOperation { | ||
function perform(a:Int, b:Int):Int; | ||
} | ||
|
||
class Ops { | ||
static public final add:MathOperation = (a, b) -> a + b; | ||
static public final subtract:MathOperation = (a, b) -> a - b; | ||
|
||
static public function performMathOperation(operation:MathOperation) { | ||
return operation.perform(8, 4); | ||
} | ||
} | ||
|
||
class Main { | ||
static function main() { | ||
var result = Ops.performMathOperation(Ops.add); | ||
trace('Add: ${result}'); | ||
|
||
result = Ops.performMathOperation(Ops.subtract); | ||
trace('Subtract: ${result}'); | ||
|
||
result = Ops.performMathOperation(multiply); | ||
trace('Multiply: ${result}'); | ||
|
||
result = Ops.performMathOperation(function(a, b):Int { | ||
return Std.int(a / b); | ||
}); | ||
trace('Divide: ${result}'); | ||
} | ||
|
||
static function multiply(a, b):Int { | ||
return a * b; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--main Main | ||
--jvm bin/run.jar | ||
--cmd java -jar bin/run.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Main.hx:17: Add: 12 | ||
Main.hx:20: Subtract: 4 | ||
Main.hx:23: Multiply: 32 | ||
Main.hx:28: Divide: 2 |