| 1 |
package inference.guava; |
| 2 |
|
| 3 |
import java.io.Serializable; |
| 4 |
import java.util.Map; |
| 5 |
import java.util.function.Function; |
| 6 |
import java.util.stream.Collector; |
| 7 |
|
| 8 |
@SuppressWarnings("") // Just check for crashes. |
| 9 |
public class Bug7 { |
| 10 |
static <T, K, V> Collector<T, ?, MyMap<K, V>> toMap( |
| 11 |
Function<? super T, ? extends K> keyFunction, |
| 12 |
Function<? super T, ? extends V> valueFunction) { |
| 13 |
return Collector.of( |
| 14 |
MyMap.Builder<K, V>::new, |
| 15 |
(builder, input) -> |
| 16 |
builder.put(keyFunction.apply(input), valueFunction.apply(input)), |
| 17 |
MyMap.Builder::combine, |
| 18 |
MyMap.Builder::build); |
| 19 |
} |
| 20 |
|
| 21 |
public abstract static class MyMap<K, V> implements Map<K, V>, Serializable { |
| 22 |
public static class Builder<K, V> { |
| 23 |
|
| 24 |
public Builder() {} |
| 25 |
|
| 26 |
public Builder<K, V> put(K key, V value) { |
| 27 |
throw new RuntimeException(); |
| 28 |
} |
| 29 |
|
| 30 |
Builder<K, V> combine(Builder<K, V> other) { |
| 31 |
throw new RuntimeException(); |
| 32 |
} |
| 33 |
|
| 34 |
public MyMap<K, V> build() { |
| 35 |
throw new RuntimeException(); |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
} |