aspose file tools
The moose likes Java in General and the fly likes Array.newInstance documentation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Array.newInstance documentation" Watch "Array.newInstance documentation" New topic
Author

Array.newInstance documentation

Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

Does the example they give make any sense to you guys? The first line seems to create an array with one element of value length, then this array is passed in where an int should be?

newInstance

public static Object newInstance(Class<?> componentType, int length)
throws NegativeArraySizeException

Creates a new array with the specified component type and length. Invoking this method is equivalent to creating an array as follows:

int[] x = {length};
Array.newInstance(componentType, x);

Parameters:
componentType - the Class object representing the component type of the new array
length- the length of the new array

Returns:
the new array
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16817
    
  19

Read this part again....

Invoking this method is equivalent to creating an array as follows:



In this case, the "equivalent" being referred to is an overloaded method -- a method that allows you to declare a multidimensional array. What the example is, is what this method does. It is not an example of how to use this method.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array.newInstance documentation
 
Similar Threads
how to return an array from a method ..
Misc topics
Multidimensional array copy
resize two arrays ... guide me ...
Should @SuppressWarnings be used?