引用类的实例方法
package LambdaTest.LambdaTest03; /** * FileName: MyStringDemo * Author: lps * Date: 2022/4/5 15:09 * Sign:刘品水 Q:1944900433 */ public class MyStringDemo { public static void main(String[] args) { // useMyString((String s,int x,int y)->s.substring(x,y)); useMyString((s,x,y)->s.substring(x,y)); useMyString(String::substring); //Lambda表达式被类的实例方法替代时 //第一个参数作为调用者 //后面的的参数全部传递给该方法做参数 } private static void useMyString(MyString my) { String s = my.mySubString("HelloWorld", 2, 5); System.out.println(s); } }
package LambdaTest.LambdaTest03; /** * FileName: MyString * Author: lps * Date: 2022/4/5 15:08 * Sign:刘品水 Q:1944900433 */ public interface MyString { String mySubString(String s,int x,int y); }