JDK-4093690 : rfe: About Java array Dynamics
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.1.4
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_95
  • CPU: x86
  • Submitted: 1997-11-18
  • Updated: 1998-04-08
  • Resolved: 1998-04-08
Related Reports
Duplicate :  
Description

Name: rm29839			Date: 11/18/97


Hi, in my free time I'm developing a Command-Line Interpreter for a slightly modified 
subset of the Java Language Specification, more specifically all possible expansions of 
Expressions and Local Variable Declarations.  This I think is a very powerful devolopper 
tool for trying out expressions and getting results immediately.

I'm writing all this in Java and I'm basing the interpreter engine on the Reflection library. 
This way users will get command-line access to the complete Java library. But as I advance 
in the development I've come upon a few shortcomings of the library that I think all 
programmers would benefit from if they were implemented.
Here is my wishlist:

* java.lang.Class should have the following method:

	public native Class getArrayClass(int[] Dims)

	Returns:
	* a Class object representing an array with 'Dims.size()' Dimensions of the class
	  represented by the instance of Class where the method was called.

	Example:
		Class StringClass=Class.forName("java.lang.String");

		int[] Dims={3, 4};
		Class StringArrayClass=StringClass.getArrayClass(Dims);
		Object StringArray=StringArrayClass.newInstance();

		// Ovbiously this seems of little use since it's impossible to initialize
		// the array. But that's when the need for an ArrayManager class comes
		// into existence.

*class java.util.ArrayManager {
	public ArrayManager(Object array) { //?? };

	// Returns an array of integers where 'intarr.size()' is the number of dimensions
	// and 'intarr[i]' is the length for dimension 'i'.
	public native int[] getDims();

	// Set values inside the array according to 'Position'.
	public native set(int[] Position, Object Value);

	// Get values inside the array according to 'Position'.
	public native Object get(int[] Position);
 }

* The class described avobe would throw the usual kind of Exceptions and hopefuly it could
  be smart enough to recognize arrays of primitive types and do the appropriate convertions
  to instances of their representative java.lang.Number classes.

I think that's it for now. I hope you take my
(Review ID: 19905)
======================================================================

Comments
WORK AROUND Name: rm29839 Date: 11/18/97 Here is my wishlist: * java.lang.Class should have the following method: public native Class getArrayClass(int[] Dims) Returns: * a Class object representing an array with 'Dims.size()' Dimensions of the class represented by the instance of Class where the method was called. Example: Class StringClass=Class.forName("java.lang.String"); int[] Dims={3, 4}; Class StringArrayClass=StringClass.getArrayClass(Dims); Object StringArray=StringArrayClass.newInstance(); // Ovbiously this seems of little use since it's impossible to initialize // the array. But that's when the need for an ArrayManager class comes // into existence. *class java.util.ArrayManager { public ArrayManager(Object array) { //?? }; // Returns an array of integers where 'intarr.size()' is the number of dimensions // and 'intarr[i]' is the length for dimension 'i'. public native int[] getDims(); // Set values inside the array according to 'Position'. public native set(int[] Position, Object Value); // Get values inside the array according to 'Position'. public native Object get(int[] Position); } * The class described avobe would throw the usual kind of Exceptions and hopefuly it could be smart enough to recognize arrays of primitive types and do the appropriate convertions to instances of their representative java.lang.Number classes. I think that's it for now. I hope you take my ======================================================================
11-06-2004

EVALUATION The proposed 'java.lang.Class.getArrayClass' method seems like it would be a useful addition, however, the same could be said for analogous operations to synthesize other classes and interfaces at runtime. This could get complicated very quickly, and is not in the spirit of the current reflection design. Note also that the proposed class 'java.util.ArrayManager' is not needed. There are already operations to manipulate array values provided in 'java.lang.reflect.Array'. william.maddox@Eng 1998-03-02 getArrayClass() is 4071439. The rest of the RFE doesn't sound doable. Closing this as a duplicate of 4071439. anand.palaniswamy@Eng 1998-04-08
02-03-1998