• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array.newInstance documentation  RSS feed

 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!