Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Accessing array classes

Thread view: 
ohoehle - 28 Nov 2006 13:02 GMT
Hi!

There is a given object of type java.lang.Class and I want to get the
array class corresponding to my class, aka the Class object with a
componentType identical to the given Class object.

I did it this way...

public static Class getArrayClass(Class componentType) {
  return Array.newInstance(componentType, 0).getClass();
}

but creating an array just to get its class is &§&%/()/%$/&%$!!! in my
eyes...

Do you know a better solution?

Regards
Oliver
Chris Uppal - 30 Nov 2006 14:10 GMT
> There is a given object of type java.lang.Class and I want to get the
> array class corresponding to my class, aka the Class object with a
> componentType identical to the given Class object.

This is something of a FAQ (not to mention something of a stupid omission from
java.lang.Class).  One discussion of the issue which I remember ('cos I took
part in it -- and because it went memorably and entertainingly wrong after a
while ;-) is here:

http://groups.google.co.uk/group/comp.lang.java.programmer/browse_frm/thread/5b9
8910e683da220


   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.