I have the method which accepts Field
and Object
public String format(Field field, Object o) {....}
I want to know if field can be cast to number.
I have noticed that if write something like this(for long primitive):
field.getType().isAssignableFrom(long.class)
returns true
but
field.getType().isAssignableFrom(Long.class)
returns false
and
field.getType().isAssignableFrom(Number.class)
returns false
too
Also
field.getType().cast(Number.class)
returns ClassCastException
Please help to write method which will return true
if field is actually number(int
, long
, byte
...,also all wrappers) and false
in other cases.
Aucun commentaire:
Enregistrer un commentaire