ラムダ式は変数とメソッドで定義できると思うのですが、どちらがよいとか、
こういう場合はこっちで、こういう場合はこっち、といったことはあるのでしょうか??
それとも同じでしょうか?
java
1public static void main(String[] args) { 2 3 List<String> list = Arrays.asList("a", "b", "c", "d"); 4 list.stream().map(toUpper).forEach(System.out::println); 5 list.stream().map(toUpper()).forEach(System.out::println); 6 7 } 8 static Function<String, String> toUpper(){ 9 return s -> s.toUpperCase(); 10 } 11 12 static Function<String, String> toUpper = s -> s.toUpperCase();
上記のtoUpper()と、toUpperは同じ動作になるかと思いますが、
厳密には何か違う点があるのでしょうか。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/04/27 22:45
2017/04/28 01:35
退会済みユーザー
2017/04/29 02:12