Last active
July 13, 2017 02:54
-
-
Save hishidama/2b5dda47809333d0763c7a63e3145213 to your computer and use it in GitHub Desktop.
メソッド参照できる・できない
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
package example; | |
// https://ideone.com/cx8hsF | |
public class MethodReferenceExample { | |
public static void main(String[] args) throws java.lang.Exception { | |
// your code goes here | |
Test test11 = String::trim; | |
// Test test12 = Hogehoge::trim; // NG | |
Hogehoge h = new Hogehoge(); | |
Test test13 = h::trim; | |
Test test14 = Hogehoge::staticTrim; | |
// Test2 test21 = String::trim; // NG | |
Test2 test22 = Hogehoge::trim; | |
} | |
} | |
class Hogehoge { | |
String trim(String v) { | |
return v.trim(); | |
} | |
static String staticTrim(String v) { | |
return v.trim(); | |
} | |
} | |
interface Test { | |
String doSomething(String v); | |
} | |
interface Test2 { | |
String doSomething(Hogehoge hh, String v); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment