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 2007

Tip: Looking for answers? Try searching our database.

Method.invoke() with one arg compiles despite method signature

Thread view: 
lyallex - 29 Sep 2007 12:03 GMT
Hi

This has got me stumped

jdk1.5.0_10

I can compile and run the code for RunTests and associated classes at
http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html

However the Java 2 Platform Standard Ed. 5.0 javadoc for Method shows
the following signature for invoke

Object invoke(Object obj, Object... args)

The particular bit of the code that is causing me a problem is

...
try {
   m.invoke(null);
...

I have looked at the code for Method and there is only one 2 arg method
called invoke. How then am I managing to compile and run the
aforementioned code ... surely the compiler should flag this as a
compile time error. Obviously I'm missing something but I can't see what.

What am I missing ? ...

Thanks in advance

Duncan
Owen Jacobson - 29 Sep 2007 12:06 GMT
> However the Java 2 Platform Standard Ed. 5.0 javadoc for Method shows
> the following signature for invoke
>
> Object invoke(Object obj, Object... args)

> try {
>     m.invoke(null);
[quoted text clipped - 4 lines]
> aforementioned code ... surely the compiler should flag this as a
> compile time error. Obviously I'm missing something but I can't see what.

The second argument is a varargs argument, which is translated to an
array automatically by the compiler.  If omitted, the varargs argument
is populated with an empty array.

-Owen
lyallex - 29 Sep 2007 12:17 GMT
>> However the Java 2 Platform Standard Ed. 5.0 javadoc for Method shows
>> the following signature for invoke
[quoted text clipped - 11 lines]
>
> The second argument is a varargs argument,

Oh ******, and I thought I had got a handle on all the new 1.5 features.

Thanks for that

Duncan
Mike Schilling - 29 Sep 2007 19:33 GMT
>>> However the Java 2 Platform Standard Ed. 5.0 javadoc for Method
>>> shows the following signature for invoke
[quoted text clipped - 15 lines]
> Oh ******, and I thought I had got a handle on all the new 1.5
> features.

The ones that were introduced to make your life easier? :-)
lyallex - 29 Sep 2007 20:33 GMT
>>>> However the Java 2 Platform Standard Ed. 5.0 javadoc for Method
>>>> shows the following signature for invoke
[quoted text clipped - 3 lines]
>
> The ones that were introduced to make your life easier? :-)

:-) Yea, they're the ones. Sometimes I think that some of these
'enhancements' are only invented to give anal interviewers something to
pick up on to make themselves feel superior when they are interviewing
you for some squalid little job in some ghastly sweatshop.

Never give up, never surrender.

Galaxy Quest, the best film EVER ;-)
Roedy Green - 29 Sep 2007 12:16 GMT
>Object invoke(Object obj, Object... args)
>
[quoted text clipped - 7 lines]
>I have looked at the code for Method and there is only one 2 arg method
>called invoke.

I had to read your post several time to figure out why you thought
that code should not work.

Object ... arg --- the parm list can also be empty (unlike the ...
ellipsis in English). This effectively gives you a 1-arg constructor.

Signature

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

lyallex - 29 Sep 2007 14:52 GMT
>> Object invoke(Object obj, Object... args)
>>
[quoted text clipped - 10 lines]
> I had to read your post several time to figure out why you thought
> that code should not work.

Really, I thought I'd made it quite clear, oh well, it's all sorted now.


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.