Created
January 31, 2017 18:21
-
-
Save Burdzi0/b63a440e314205e92af9d840e9d6e6d3 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 lambda.references; | |
public interface StringFunc { | |
String func(String s); | |
} | |
public class MyStringOps { | |
static String strReverse(String str) { | |
String result = ""; | |
int i; | |
for (i = str.length() - 1; i >= 0; i--) { | |
result += str.charAt(i); | |
} | |
return result; | |
} | |
} | |
public class MethodRefDemo { | |
static String stringOp(StringFunc sf, String s) { | |
return sf.func(s); | |
} | |
public static void main(String[] args) { | |
String inStr = "Wyrażenia lambda rozszerzają możliwości Javy"; | |
String outStr; | |
outStr = stringOp(MyStringOps::strReverse, inStr); | |
//outStr = MyStringOps.strReverse(inStr); | |
System.out.println("Łańcuch początkowy: " + inStr); | |
System.out.println("Łańcuch odwrócony: " + outStr); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment