How do I encapsulate code that uses 'instanceof' , I have a lot of types to judge, how do I simplify them ? For example using for loops.
if (obj instanceof UserLogin) {
continue;
}
if (obj instanceof MultipartFile) {
continue;
}
if (obj instanceof Part) {
continue;
}
if (obj instanceof HttpServletRequest) {
continue;
}
if (obj instanceof HttpServletResponse) {
continue;
}
//【Simplify using for loops :】
My idea is: add the classes you want to judge to a ignoreList collection and iterate using Instanceof. But have error :Cannot resolve symbol 'get'
public boolean shouldIgnore(Object obj) {
for (int i = 0; i < ignoreList.size(); i++) {
if (obj instanceof ignoreList.get (i) ){
return true;
}
}
return false;
}