2

I am using reflection to get all methods parameters names.

The problem is when one of the parameters is of type: the.package.myobject [] (array)

String name = method.getParameterTypes()‬[0].getName()

I get: [the.package.myobject;] //letter L and symbol ;

how can I get pure type name? (without substringing)

2 Answers 2

8

You need to check type.isArray() and, if yes, use getComponentType().

final Class<?> c = method.getParameterTypes()[0];
final String name = (c.isArray()? c.getComponentType() : c).getName();
Sign up to request clarification or add additional context in comments.

Comments

1

Most likely what you want is

Class firstType = method.getParameterTypes()‬[0];

// will be null if not an array.
Class firstComponentType = firstType.getComponentType();

1 Comment

sorry it was a typo, please see my post again.

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.