-
Enhancement
-
Resolution: Fixed
-
P2
-
7
-
b100
-
unknown
-
generic
-
Verified
Quoting from project coin proposal at the following URL:
http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000316.html
"When a programmer tries to invoke a varargs (variable
arity) method with a non-reifiable varargs type, the compiler currently
generates an "unsafe operation" warning. This proposal moves the warning
from the call site to the method declaration."
BEFORE:
static <T> List<T> asList(T... elements) { ... }
static List<Callable<String>> stringFactories() {
Callable<String> a, b, c;
...
// Warning: "uses unchecked or unsafe operations"
return asList(a, b, c);
}
AFTER (1):
// Warning: "enables unsafe generic array creation"
static <T> List<T> asList(T... elements) { ... }
static List<Callable<String>> stringFactories() {
Callable<String> a, b, c;
...
// Warning: "uses unchecked or unsafe operations"
return asList(a, b, c);
}
AFTER (2):
@SuppressWarnings("generic-varargs")
static <T> List<T> asList(T... elements) { ... } //no warning
static List<Callable<String>> stringFactories() {
Callable<String> a, b, c;
...
// no warning
return asList(a, b, c);
}
http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000316.html
"When a programmer tries to invoke a varargs (variable
arity) method with a non-reifiable varargs type, the compiler currently
generates an "unsafe operation" warning. This proposal moves the warning
from the call site to the method declaration."
BEFORE:
static <T> List<T> asList(T... elements) { ... }
static List<Callable<String>> stringFactories() {
Callable<String> a, b, c;
...
// Warning: "uses unchecked or unsafe operations"
return asList(a, b, c);
}
AFTER (1):
// Warning: "enables unsafe generic array creation"
static <T> List<T> asList(T... elements) { ... }
static List<Callable<String>> stringFactories() {
Callable<String> a, b, c;
...
// Warning: "uses unchecked or unsafe operations"
return asList(a, b, c);
}
AFTER (2):
@SuppressWarnings("generic-varargs")
static <T> List<T> asList(T... elements) { ... } //no warning
static List<Callable<String>> stringFactories() {
Callable<String> a, b, c;
...
// no warning
return asList(a, b, c);
}
- relates to
-
JDK-7196160 Project Coin: Allow @SafeVarargs on private methods
- Closed
-
JDK-6993978 Project Coin: Compiler support of annotation to reduce varargs warnings
- Closed
-
JDK-7006129 Project Coin: Annotation type to reduce varargs warnings
- Closed
-
JDK-8069254 Warning issued despite @SafeVarargs annotation on constructor
- Closed