I have following code and now I have type, but I need to have some kind of switch to know if type is for example of String and then do handling for strings. So how can I check if Type t is type of String?
Type t = bean.getClass().getDeclaredField(fieldName).getType();
Do you want to do a name check or an object-based check?
Since Class
implements Type
, you can actually go directly and do the equals against String.class
For instance: if (t.equals(String.class))
If, however, you want to do a check based on name, then first check if t is an instance of Class, and then cast it to Class, obtain the full type name, and compare.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With