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 / November 2007

Tip: Looking for answers? Try searching our database.

reflection and method with (int...) params

Thread view: 
devphylosoff - 11 Nov 2007 17:53 GMT
hello

i have constructor :
public ClassName(int...) { }

and I invoke somewhere:
ClassType.getConstructor(tab).newInstance(tab2);

where tab is "Class []" of "int []"
and tab2 is "int []"

I receive java.lang.NoSuchMethodException
why ?

if i change
  public ClassName(int...){}
to
 public ClassName(int, int, int, int) {}
all is ok

method getConstructors() see my constructor as:
public transient ClassName(int[])  public transient ClassName(int[])

any idea ?
Joshua Cranmer - 11 Nov 2007 18:43 GMT
> hello
>
[quoted text clipped - 20 lines]
>
> any idea ?

Can you provide a SSCCE (see <http://www.physci.org/codes/sscce.html>)?

My guess is that this is what you want to do:
ClassName.class.getConstructor(int[].class).newInstance(tab2);

But I can't see what's failing based on only what you have written--the
error is as often in what is not provided as it is in what is provided.

Signature

Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth

Arne Vajhøj - 12 Nov 2007 02:28 GMT
> i have constructor :
> public ClassName(int...) { }
[quoted text clipped - 18 lines]
>
> any idea ?

public class ConLkUp {
    public ConLkUp(int... ia) {
        for(int i : ia) {
            System.out.println(i);
        }
    }
    public static void main(String[] args) throws Exception {
        ConLkUp o = ConLkUp.class.getConstructor(new Class[] {
int[].class }).newInstance(new int[] {1, 2, 3} );
    }
}

Arne


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



©2009 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.