General Queries on Java API

S

Sameer

Please see the following code snippets:

1)
public Method getMethod(String name,
Class... parameterTypes)
throws NoSuchMethodException,
SecurityException

What is the meaning of ... after Class?
Does it indicate variable number of parameters?
But the method is supported Since JDK1.1.


2) Class c = String.class;
This is a code snippet from Reflection Java Tutorial.
From where .class comes? It is not a static field in String class.
Also it is not inherited from Object.
 
N

Nils Bandener

Sameer said:
public Method getMethod(String name,
Class... parameterTypes)
throws NoSuchMethodException,
SecurityException

What is the meaning of ... after Class?
Does it indicate variable number of parameters?

Yes, it does.
But the method is supported Since JDK1.1.

Before Java 5, the method hat the signature (String name, Class []
parameterTypes). And in fact, Java 5 internally converts the arguments
given for the ellipsis parameter to an array containing these values.
So, the signatures mean the same.
2) Class c = String.class;
This is a code snippet from Reflection Java Tutorial.
From where .class comes? It is not a static field in String class.
Also it is not inherited from Object.

..class is not a static field, but a special keyword that returns the
Class object of the particular class. So, the snippet above will give
you the class object for the String class.

Bye

Nils
 
R

Roedy Green

public Method getMethod(String name,
Class... parameterTypes)

It behaves just like

Class[] parameterTypes

except you can say

Dog.class, Cat.class, Rabbit.class
instead of
new Class[] { Dog.class, Cat.class, Rabbit.class }

when you invoke the method.
 

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
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top