Avatar of headzoo
headzoo
 asked on

Java: Class.getConstructor and Primative Arrays

Hi,
Pretty new to Java. I'm trying to use reflection to create an instance of a class, and the class constructor takes a primitive array as a parameter.

Here's what my code looks like:

class A
{
      public A(Integer i, long[] s)
      {
            // Do stuff here
      }
      
      public static void main(String[] args)
      {
            Class cla = A.class;
            Constructor con = cla.getConstructor(Integer.class, long[].class);
      }
}

Clearly this won't compile, because of the long[].class. So how do I tell the getConstructor() method that one of the parameters is an array of a primitive type?
Java

Avatar of undefined
Last Comment
cmalakar

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
cmalakar

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Bart Cremers

The way to get the constructor is correct. You only need to handle the exceptions thrown.
SOLUTION
cmalakar

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck