| 1 |
package inference.bug8; |
| 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 Bug8 { |
| 10 |
|
| 11 |
static <T1, K1, V1> Collector<T1, ?, MyMap<K1, V1>> toImmutableMap( |
| 12 |
Function<? super T1, ? extends K1> keyFunction, |
| 13 |
Function<? super T1, ? extends V1> valueFunction) { |
| 14 |
return Collector.of( |
| 15 |
MyMap.Builder<K1, V1>::new, |
| 16 |
(builder, input) -> |
| 17 |
builder.put(keyFunction.apply(input), valueFunction.apply(input)), |
| 18 |
MyMap.Builder::combine, |
| 19 |
MyMap.Builder::build); |
| 20 |
} |
| 21 |
|
| 22 |
static <T, K, V> Collector<T, ?, MyBiMap<K, V>> toImmutableBiMap( |
| 23 |
Function<? super T, ? extends K> keyFunction, |
| 24 |
Function<? super T, ? extends V> valueFunction) { |
| 25 |
return Collector.of( |
| 26 |
MyBiMap.Builder<K, V>::new, |
| 27 |
(builder, input) -> |
| 28 |
builder.put(keyFunction.apply(input), valueFunction.apply(input)), |
| 29 |
MyBiMap.Builder::combine, |
| 30 |
MyBiMap.Builder::build, |
| 31 |
new Collector.Characteristics[0]); |
| 32 |
} |
| 33 |
|
| 34 |
abstract static class ShimMap<K, V> extends MyMap<K, V> {} |
| 35 |
|
| 36 |
public interface BiMap<K, V> extends Map<K, V> {} |
| 37 |
|
| 38 |
public abstract static class MyBiMap<K, V> extends ShimMap<K, V> implements BiMap<K, V> { |
| 39 |
public static final class Builder<K, V> extends MyMap.Builder<K, V> { |
| 40 |
public Builder() {} |
| 41 |
|
| 42 |
@Override |
| 43 |
public MyBiMap.Builder<K, V> put(K key, V value) { |
| 44 |
throw new RuntimeException(); |
| 45 |
} |
| 46 |
|
| 47 |
@Override |
| 48 |
MyBiMap.Builder<K, V> combine(MyMap.Builder<K, V> builder) { |
| 49 |
super.combine(builder); |
| 50 |
return this; |
| 51 |
} |
| 52 |
|
| 53 |
@Override |
| 54 |
public MyBiMap<K, V> build() { |
| 55 |
throw new RuntimeException(); |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
public abstract static class MyMap<K, V> implements Map<K, V>, Serializable { |
| 61 |
public static class Builder<K, V> { |
| 62 |
public Builder() {} |
| 63 |
|
| 64 |
public MyMap.Builder<K, V> put(K key, V value) { |
| 65 |
throw new RuntimeException(); |
| 66 |
} |
| 67 |
|
| 68 |
MyMap.Builder<K, V> combine(MyMap.Builder<K, V> other) { |
| 69 |
throw new RuntimeException(); |
| 70 |
} |
| 71 |
|
| 72 |
public MyMap<K, V> build() { |
| 73 |
throw new RuntimeException(); |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
} |