public class MyTest {
public static void printValur(String str){
System.out.println( "print value : " +str);
}
public static void main(String[] args) {
List<String> al = Arrays.asList( "a" , "b" , "c" , "d" );
al.forEach(AcceptMethod::printValur);
//下面的方法和上面等價的
Consumer<String> methodParam = AcceptMethod::printValur; //方法參數
al.forEach(x -> methodParam.accept(x)); //方法執行accept
}
}
|