File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed
main/java/io/javaalmanac/snippets/language
test/java/io/javaalmanac/snippets/language Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,11 @@ static void classMethod() {
3333 System .out .println ("classMethod" );
3434 }
3535
36+ static int classMethodWithReturn (String parameter ) {
37+ System .out .println ("classMethodWithReturn " + parameter );
38+ return 42 ;
39+ }
40+
3641 }
3742
3843 public static void main (String [] args ) {
@@ -57,6 +62,11 @@ public static void main(String[] args) {
5762 Runnable runnable2 = Foo ::classMethod ;
5863 runnable2 .run ();
5964
65+ // Method return values are ignored if the functional interface method
66+ // has return type void
67+ Consumer <String > consumer2 = Foo ::classMethodWithReturn ;
68+ consumer2 .accept ("hello" );
69+
6070 // Array constructor as reference
6171 IntFunction <Foo []> function = Foo []::new ;
6272 Foo [] array = function .apply (42 );
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ void run_main() throws Exception {
1414 instanceMethod
1515 instanceMethod hello
1616 classMethod
17+ classMethodWithReturn hello
1718 42
1819 """ );
1920 }
You can’t perform that action at this time.
0 commit comments