1

I am trying to extract parameter types from a java.lang.reflect.Constructor<T> object, by using the getParameterTypes() method

The constructor looks like this :

 public SearchParameters(boolean doStaticBoosting, boolean doRewrites, boolean doCatalogsFacet, long userId,
                            Filter catalogsFilter, boolean doCatalogsFilterTypeFacet, boolean doSocialBoosting,
                            long[] categoryFilteringId)

Now when I invoke this method what I get the following paramter types :

enter image description here

As you see the last Class parameter is really messed up and defined as

class [J

where in fact I want it to be an long[].class. I need to reconstruct this object later , and of course I cant do that based only on that parameter info I got.

Roman
  • 7,933
  • 17
  • 56
  • 72

3 Answers3

4

That's not messed up at all. That's just the string representation of long[].class:

System.out.println(long[].class); // class [J

Unless you really need to keep the string representation somehow, you should just keep hold of the value as a Class<?> and all should be well.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
2

That is the name of the long[] class. Try this:

    long[] longs = {1L, 2L};
    System.out.println("Name is: " + longs.getClass().getName());

This prints:

Name is: [J

You can get the names of all the primitive array classes from the Javadocs of Class.getName().

Keppil
  • 45,603
  • 8
  • 97
  • 119
1

class [J is the name of long[].class. Check out Class.getName() JavaDoc.

Moreover you can create an instance of long[].class by using this name, see: How to create a Class of primitive array?

Community
  • 1
  • 1
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674