Here's a minimal example of the code I'm working with:
public class Temp {
enum SomeEnum {}
private static final Map<SomeEnum, String> TEST = new EnumMap<>(
Arrays.stream(SomeEnum.values())
.collect(Collectors.toMap(t -> t, a -> "")));
}
The compiler output is:
Temp.java:27: error: cannot infer type arguments for EnumMap<>
private static final Map<SomeEnum, String> TEST = new EnumMap<>(Arrays.stream(SomeEnum.values())
^
I have found that this can be worked around by replacing t -> t
with Function.identity()
or (SomeEnum t) -> t
, but I'm not understanding why this is the case. What limitation in javac is causing this behavior?
I originally found this issue with java 8, but have verified it still occurs with the java 11 compiler.