Created
June 29, 2017 09:25
-
-
Save fluency03/c294435157ca7f70678a782cb02bd8e7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.13.1 | |
| */ | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| public class Foo { | |
| public static void main(String[] args) { | |
| List<Bar> l = new ArrayList<>(); | |
| l.add(new Bar()); | |
| l.add(new Bar()); | |
| l.add(new Bar()); | |
| l.stream() | |
| .peek(Bar::print) // error: invalid method reference | |
| // non-static method print() cannot be referenced from a static context | |
| .forEach(Bar::print); // error: invalid method reference | |
| // non-static method print() cannot be referenced from a static context | |
| Bar b = new Bar(); | |
| b.print(); | |
| Bar.print(b); | |
| } | |
| } | |
| class Bar { | |
| public void print() { | |
| System.out.println("this: " + this); | |
| } | |
| public static void print(Bar b) { | |
| System.out.println("bar: " + b); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment