For instance, when to use
GetterUtil.getBoolean()
and when
ParamUtil.getBoolean()?
Are both same, or is it expected to be used differently according to a parameter, a variable, etc? Can you give some examples for both?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Both are util methods to avoid Null-Pointer Exceptions.
GetterUtilinternally returns the default type and does the casting too. So in case where someone has passed anullvalue, it will return default value of the type.Example:
Assume you have a
Stringvalue"true", and you are expecting it will always be of typeboolean. So you useGetterUtil.getBoolean("true")which will internally do the casting to boolen and return the value asboolean-true. Incase someone passes rubbish characters like"tr", it will be converted toboolean-false.As mentioned
ParamUtildoes the same treatment withrequestparameters.ParamUtilinternally uses theGetterUtilto have the above behaviour. It first retrieves the parameter (which always would be a string) and then passes it toGetterUtil.getType()method and in turn returns the proper type.