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 / September 2005

Tip: Looking for answers? Try searching our database.

General Queries on Java API

Thread view: 
Sameer - 18 Sep 2005 10:17 GMT
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.
Nils Bandener - 18 Sep 2005 10:47 GMT
> public Method getMethod(String name,
>                         Class... parameterTypes)
[quoted text clipped - 3 lines]
> 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
Roedy Green - 18 Sep 2005 18:11 GMT
>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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Roedy Green - 18 Sep 2005 18:12 GMT
>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.

see http://mindprod.com/jgloss/classforname.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



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.