Skip to content

Instantly share code, notes, and snippets.

@Burdzi0
Created January 31, 2017 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Burdzi0/b63a440e314205e92af9d840e9d6e6d3 to your computer and use it in GitHub Desktop.
Save Burdzi0/b63a440e314205e92af9d840e9d6e6d3 to your computer and use it in GitHub Desktop.
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