JDK-4071439 : (reflect) Need API to create array classes
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 1.1,1.1.4,1.1.5,1.1.6
  • Priority: P5
  • Status: Closed
  • Resolution: Won't Fix
  • OS:
    solaris_2.5,solaris_2.6,windows_95,windows_nt solaris_2.5,solaris_2.6,windows_95,windows_nt
  • CPU: x86,sparc
  • Submitted: 1997-08-13
  • Updated: 2021-02-24
  • Resolved: 2021-02-24
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
An API is needed to be able to create array classes.  

A method can be added to java.lang.Class:

   public Class getArrayType(int dimensions);

It would return a Class class for the array of that class with the 
appropriate number of dimensions.  If applied to an Array class
it would return a Class an array with a number of dimensions
equal to the existing array class plus the dimensions specified.
If applied to any of the primitive types it should create the
appropriately typed array.

This method is a campanion to Class.getComponentType.

Related methods for reflecting upon arrays in in java.lang.reflect.Array.

Comments
The work done under JDK-8210031 added Class.arrayType, which partially satisfies the requested enhancement here. Closing as will not fix.
24-02-2021

EVALUATION I assume the support in 1.1 is sufficient? java.lang.reflect.Array.newInstance(Class, int[]) Or are you looking for more functionality? tom.rodriguez@Eng 1997-12-18 An API is needed to be able to create array classes. The requested functionality was to get an array class, not an instance of an array class. The following is a test case that demonstrates the requested functionality. class A { }; public class createArrayClass { /* This is the interface requested to belong to class Class. */ static public Class getArrayType(Class cl, int dimensions) { // This workaround is unsatisfactory since it // generates an object in order to get the class. return java.lang.reflect.Array.newInstance(cl, new int[dimensions]).getClass(); } public static void main(String argv[]) { System.out.println("This generates an instance of an array."); System.out.println(java.lang.reflect.Array.newInstance(A.class, 3).toString()); System.out.println("Get a two-dimensional array class"); Class a2 = getArrayType(A.class, 2); System.out.println(a2.toString()); System.out.println("Get a 3-dimensional array class"); Class a3 = getArrayType(A.class, 3); System.out.println(getArrayType(A.class, 3).toString()); //this functionality was explicitly requested. System.out.println("Get a 6-dimensional array class"); System.out.println(getArrayType(a3, 3).toString()); } } joseph.fialli@East 1997-12-22 This seems like something reasonable to add to the API since it's a hole. We'll try to get this fixed for 1.2beta4. tom.rodriguez@Eng 1998-03-31 Lowering the priority because in 1.2beta4 this can be done with the new Class.forName() that takes a loader. We might want to revisit this in the next feature release, perhaps? anand.palaniswamy@Eng 1998-05-06
06-05-1998

WORK AROUND In 1.2beta4 or later, you can use Class.forName(String,boolean,ClassLoader) to achieve the same goal, though in a more roundabout fashion. anand.palaniswamy@Eng 1998-05-06
06-05-1998