aspose file tools*
The moose likes Java in General and the fly likes How can I... make a random number of arguments call? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How can I... make a random number of arguments call?" Watch "How can I... make a random number of arguments call?" New topic
Author

How can I... make a random number of arguments call?

Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
(Whoa, that's what 'random' means, like in 'random acces')

It's not really important (maybe). I'm just learning, and I'm a begginer, and I haven't got to the reflection yet, but I just have ideas , and I wonder if this is possible at all, maybe even how?

So... can I call a method programmatically? I think that probably I can, with reflection. Can I call an arbitrary number of arguments programmatically, or just arbitrary arguments? (not var-args)

Actually I do have some idea that attracts me all the time in that direction, and that's why I ask this question which is way over my current knowledge, so that I can sleep better. Thanks.

: (Like for example that elements of an ArrayList are each solo one argument in a method call. Not that ArrayList is one argument, but arguments become all and each elements separatedly, of an ArrayList, together with the variable number of arguments, call, and the cherry on top. Hm?)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14110
    
  16

The reflection API allows you to discover things about Java classes, such as which constructors, methods and fields a class has, at runtime, and it makes it also possible to call constructors and methods on objects in a dynamic way (i.e. without the need to know beforehand, at compile time, which methods there are).

Have a look at this part of Sun's Java tutorials: Trail: The Reflection API


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
I found this for the begining, which answers a part of my wondering. ( may-be even all )



This little program is a complete, if minimal, test framework. It takes a list of class names on the command line. For each class name, it instantiates the class using its parameterless constructor and invokes a parameterless method called test. If the instantiation or invocation throws an exception, the test is deemed to have failed. The program prints each failure, followed by a summary of the test results. The reflective instantiation and invocation no longer require explicit array creation, because the getMethod and invoke methods accept a variable argument list. The program also uses the new printf facility, which relies on varargs. The program reads much more naturally than it would without varargs.


From Sun's site.
Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
Thank You mister Jesper Young.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I... make a random number of arguments call?