Hi,
I'm just wondering if any method exists in Java where I can pass a value of type object and it will check to see if the type is primitive or String. Basically I want to avoid other objects such as collections, reference objects etc. Currently I have the following code
if ((value instanceof String) || (value instanceof Byte)
|| (value instanceof Short) || (value instanceof Integer)
|| (value instanceof Long) || (value instanceof Float)
|| (value instanceof Double) || (value instanceof Boolean)
|| (value instanceof Character) || (value instanceof null){}
which will only use the value if it is a String or primitive. However, I also have to check if the value is null because a String could be null etc. This is not ideal.
Does anyone know of a method/utility class which could be used to check if the type of the object is of String or primitive. E.g. something like the following
if(ClassUtils.isPrimitive(value)){}
Thanks