Java:引用其他类的方法
1其他类成员名::方法
public class shuangliejihe {public static void main(String[] args) {ArrayList<String> a = new ArrayList<>();Collections.addAll(a,"1221","222","32","4","5","6","7","8","9","10");a.stream().filter(new Predicate<String>() {@Overridepublic boolean test (String s){return s.length() > 3;}}).forEach(System.out::println);//new....这个引用处形参是函数是接口//自己写个类,调用方法Stringoperator s = new Stringoperator();a.stream().filter(s::stringJudge).forEach(s1->System.out.println(s1));}
}
}
public class Stringoperator {public boolean stringJudge(String str) {return str.length() > 3;}
2:本类
this::方法(引用处不能是静态方法)
3父类
super::方法(引用处不能是静态方法)