In other words, check if a type is one of Integer, Double, Float, Long, Byte, Short, Boolean, Char
Asked
Active
Viewed 100 times
0
-
4Why do you even need that? Autoboxing and Unboxing works pretty well in Java. Can you describe your usage scenario? – MD Sayem Ahmed Nov 21 '13 at 08:09
-
3Take a look at this question: http://stackoverflow.com/questions/709961/determining-if-an-object-is-of-primitive-type – Nikola Yovchev Nov 21 '13 at 08:10
-
I guessing you dont want to make a big if-else block with tons of instanceof tests? – Jakob Nov 21 '13 at 08:11
-
2please vote to close. – CaiNiaoCoder Nov 21 '13 at 08:36
-
@Sayem when using reflection. java.lang.reflect.Field#getType return int.class for a int field and return Integer.class for a Integer Field, so I think we need to distinguish when int and integer are both allowed for a ambiguous field – CaiNiaoCoder Nov 21 '13 at 08:45
-
You can take a look at this question: http://stackoverflow.com/questions/709961/determining-if-an-object-is-of-primitive-type Or check Spring's ClassUtils: http://docs.spring.io/spring/docs/2.5.6/api/org/springframework/util/ClassUtils.html#isPrimitiveOrWrapper(java.lang.Class) – Nikola Yovchev Nov 21 '13 at 08:12