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 / October 2007

Tip: Looking for answers? Try searching our database.

can some explain what "new Class[0]" does

Thread view: 
Aryeh M. Friedman - 13 Oct 2007 14:33 GMT
In studying some legacy code I cam across:

Method m=this.class.getMethod(mName,new class[0])

what does the class[0] do?!?!?!!?!??  and why do it vs. something else?
Arne Vajhøj - 13 Oct 2007 15:12 GMT
> In studying some legacy code I cam across:
>
> Method m=this.class.getMethod(mName,new class[0])
>
> what does the class[0] do?!?!?!!?!??  and why do it vs. something else?

It tells getMethod to find a method with no arguments.

Arne
Richard Reynolds - 13 Oct 2007 15:14 GMT
> In studying some legacy code I cam across:
>
> Method m=this.class.getMethod(mName,new class[0])
>
> what does the class[0] do?!?!?!!?!??  and why do it vs. something else?

check the api at http://java.sun.com/j2se/1.5.0/docs/api/

the getMethod method of the Class object explains it
Lew - 13 Oct 2007 19:30 GMT
"Aryeh M. Friedman" wrote:
>> In studying some legacy code I cam across:
>>
>> Method m=this.class.getMethod(mName,new class[0])

Are you sure it doesn't say,

Method m=this.class.getMethod(mName,new Class[0])
?

BTW, "this.class" is not a very good idiom.  Bear in mind that it sets a bit
of a bad example by referring to a static member as if it were an instance
variable.

Signature

Lew

Roedy Green - 13 Oct 2007 21:42 GMT
On Sat, 13 Oct 2007 13:33:38 -0000, "Aryeh M. Friedman"
<Aryeh.Friedman@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>Method m=this.class.getMethod(mName,new class[0])
>
>what does the class[0] do?!?!?!!?!??  and why do it vs. something else?

This looks like some reflection code. I don't think you have quoted it
correctly, or at least you have left out the context that would make
it fully comprehensible.

new class[0]

Means create an dummy array of "class" objects (strange since classes
must begin with a capital letter) with no elements.

It's intent is to get you a method object you can dynamically choose
at run time by name.

see http://mindprod.com/jgloss/reflection.html

If you are a newbie, I would ignore this code for now. Reflection is
an advanced topic.

Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



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.