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