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.

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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().

Comments

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.