D
D
Dmitry2014-10-08 15:03:39
Java
Dmitry, 2014-10-08 15:03:39

Long or long in BigDecimal constructor?

I work with java.lang.reflect, in runtime I need to create a BigDecimal object,

BigDecimal.class.getConstructor(long.class);//работает
BigDecimal.class.getConstructor(Long.class);// - не работает

With the long.class parameter - everything works without problems, but when you try to initialize with Long.class, it falls out
java.lang.NoSuchMethodException: java.math.BigDecimal.<init>(java.lang.Long)

In this case, constructions of the form:
BigDecimal num = new BigDecimal((Long));
BigDecimal num = new BigDecimal((long));

Throw no exceptions.
In which direction to dig: in the direction of casting Long.class to long.class (if there is a way to convert?), Or to the constructor?
PS: All types are dynamic and not known in advance, in the case of long, there will always be Long (I am writing a mapper).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bimeg, 2014-10-08
@CTAKAH4uK

When explicitly calling a constructor, autounboxing happens. But it doesn't work in reflection.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question