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

A

Aryeh M. Friedman

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?
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Aryeh said:
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
 
L

Lew

Aryeh M. Friedman said:
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.
 
R

Roedy Green

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top