Forums Register Login

java.lang.Class object for array

+Pie Number of slices to send: Send
For example, if I have Class object from array, I can get the component type of that array by writing this code:



The problem is, if I have some Class object, how can I make the Class object for array which component type is given.

For example, how can I make Object[].class from Object.class?
+Pie Number of slices to send: Send
The Array class offers methods to do this.
+Pie Number of slices to send: Send
Then, can I write like this?



It doesn't seem to "straight" method, but I'll try it. Thanks.
+Pie Number of slices to send: Send
Oh, I misunderstood. I don't see why you'd want to do that, but yes that should work.
+Pie Number of slices to send: Send
 

Bupjae Lee wrote:Then, can I write like this?


Yes, but remember that what it will return is the array's class - ie, for:
Array.newInstance(int.class, 0).getClass()
it will return int[].class.

As long as that's what you want, you should be fine.

Winston
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 770 times.
Similar Threads
Data Retention in JSPs
Should @SuppressWarnings be used?
taglibs problem
using reflection to get getter of field?
Arrays
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:10:31.