何が欠けていますか? Integer::toString
ではなく、Object::toString
以下を使用する必要があるのはなぜですか?ジェネリックでタイプ消去と関係がありますか?Java 8のメソッドリファレンスからtoStringを呼び出す
Arrays.asList(1,2,3).stream().map(Integer::toString).forEach(System.out::println); //Won't compile
Arrays.asList(1,2,3).stream().map(Object::toString).forEach(System.out::println); //Compiles and runs fine
ところであなただけの 'は、Arrays.asList(1,2,3)を書くことができます
コンパイラは、あなたがこれを実行したい場合は知りません。 forEach(System.out :: println);または 'Stream.of(1,2,3).forEach(System.out :: println);または' IntStream.rangeClosed(1,3).forEach(System。 out :: println); –
[Java8メソッドのリファレンス(整数のtoString)であいまい型を修正する方法](http://stackoverflow.com/questions/21873829/how-to-fix-ambigous-type -on-java8-メソッド参照ce-tostring-of-an-integer) – Holger