In this case, an unbound reference to the instance method append
has the same arity, argument types, and even the return value as a reference to a static method append
, so no, you cannot resolve the ambiguity for method references. If you do not want to rename one of the methods, you should use lambda instead:
collect(StringCollector::new, (sb, s) -> sb.append(s), StringCollector::concat);
Or if you really want to use the static method:
collect(StringCollector::new, (sb, s) -> StringCollector.append(sb, s),
StringCollector::concat);
source
share