user321605
user321605

Reputation: 836

Java Reflection : internals of java.lang.reflect.Field.getDouble(object)

Does anyone know if Field.getDouble(Object) boxes and unboxes a double internally?

Thanks, RB

Upvotes: 1

Views: 346

Answers (2)

Chris Aldrich
Chris Aldrich

Reputation: 1932

Per the Sun/Oracle Reflection API tutorial:

When using reflection, type checking only occurs at runtime so there is no opportunity to box the value. ...To eliminate this exception, the problematic line should be replaced by the following invocation of Field.set(Object obj, Object value): f.set(ft, new Integer(43));

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533710

If you use Field.getDouble() on a double field, there is no auto boxing/unboxing. This method existed long before this was available.

Upvotes: 1

Related Questions