The code below contains a reference to Enum::name
(notice no type parameter).
public static <T extends Enum<T>> ColumnType<T, String> enumColumn(Class<T> klazz) {
return simpleColumn((row, label) -> valueOf(klazz, row.getString(label)), Enum::name);
}
public static <T, R> ColumnType<T, R> simpleColumn(BiFunction<JsonObject, String, T> readFromJson,
Function<T, R> writeToDb) {
// ...
}
Javac reports a warning during compilation:
[WARNING] found raw type: java.lang.Enum missing type arguments for generic class java.lang.Enum
Changing the expression to Enum<T>::name
causes the warning to go away.
However Idea flags the Enum<T>::name
version with a warning that:
Explicit type arguments can be inferred
In turn Eclipse (ECJ) doesn't report any problems with either formulation.
Which of the three approaches is correct?
On one hand raw types are rather nasty. If you try to put some other type argument e.g. Enum<Clause>::name
will cause the compilation to fails so it's some extra protection.
On the other hand the above reference is equivalent to e -> e.name()
lambda, and this formulation doesn't require type arguments.
Enviorment:
- Java 8u91
- IDEA 15.0.3 Community
- ECJ 4.5.2
List<String>
to aList<Long>
variable via aList
cast) – Fever