-
Enhancement
-
Resolution: Won't Fix
-
P4
-
None
-
5.0
-
x86
-
linux
A DESCRIPTION OF THE REQUEST :
Bug # 5101892 explains why the Array.newInstance() method can't be retrofitted to be typesafe.
Please add a new static method to the Array class that is type safe, with a signature like this one:
public static <T> T[] Array.newArray(Class<T> componentType, int length)
.
JUSTIFICATION :
Having this new type-safe method will give us a better way to write code than using the @SupressWarnings("unchecked") annotation. It will lead to cleaner code, and be a small step towards reducing caclification in the Java libraries.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect to be able to compile code that creates arrays without getting any warnings.
ACTUAL -
When I compile the code, I get warnings that I should be able to fix.
---------- BEGIN SOURCE ----------
import java.util.List;
class ArrayWarnings
{
// @SuppressWarnings("unchecked")
private List<String>[] createArray(int size)
{
return (List<String>[])Array.newInstance(List.class,size);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
@SupressWarnings("unchecked") provides a grezzy option, but -Xlint ignores it at the moment.
###@###.### 2005-1-31 03:21:51 GMT
Bug # 5101892 explains why the Array.newInstance() method can't be retrofitted to be typesafe.
Please add a new static method to the Array class that is type safe, with a signature like this one:
public static <T> T[] Array.newArray(Class<T> componentType, int length)
.
JUSTIFICATION :
Having this new type-safe method will give us a better way to write code than using the @SupressWarnings("unchecked") annotation. It will lead to cleaner code, and be a small step towards reducing caclification in the Java libraries.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect to be able to compile code that creates arrays without getting any warnings.
ACTUAL -
When I compile the code, I get warnings that I should be able to fix.
---------- BEGIN SOURCE ----------
import java.util.List;
class ArrayWarnings
{
// @SuppressWarnings("unchecked")
private List<String>[] createArray(int size)
{
return (List<String>[])Array.newInstance(List.class,size);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
@SupressWarnings("unchecked") provides a grezzy option, but -Xlint ignores it at the moment.
###@###.### 2005-1-31 03:21:51 GMT
- relates to
-
JDK-5101892 (reflect) retrofit Array.newInstance by using generics
- Closed
-
JDK-4071439 (reflect) Need API to create array classes
- Closed
-
JDK-6361355 java.lang.reflect.Array.newInstance() does not allow "run time type tokens"
- Closed