Re: Create an Object from an Array Class
- From: Joshua Cranmer <Pidgeot18@xxxxxxxxxxxxxxx>
- Date: Tue, 30 Oct 2007 21:56:55 GMT
Joshua Cranmer wrote:
What you are probable intending is something like this:
Method m = Class.forName("some.pkg.Type").getMethod("main",
String[].class);
m.invoke(null, new String[0]);
If the type of array must be determined at runtime, the following idiom can also be used:
// arrayType is a class representing the type we want.
Object array = Array.newInstance(arrayType, 0); // Empty array
Array has another overloaded version that handles multiple array dimensions.
--
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
.
- References:
- Create an Object from an Array Class
- From: Z
- Re: Create an Object from an Array Class
- From: Joshua Cranmer
- Create an Object from an Array Class
- Prev by Date: Re: Endianness of Java Virtual Machine
- Next by Date: Re: [OT]
- Previous by thread: Re: Create an Object from an Array Class
- Next by thread: Re: Create an Object from an Array Class
- Index(es):
Relevant Pages
|
|