GWT work-around for missing Class.isInstance()

好久不见. 提交于 2019-11-30 13:10:59

I use following code:

 public static <T> boolean isInstanceOf(Class<T> type, Object object) {
    try {
         T objectAsType = (T) object;
     } catch (ClassCastException exception) {
         return false;
     }
     return true;
 }

Maybe something like this would help:

boolean offerRetry(Exception exception) {
   try{
      throw exception;
   } catch (SpecException se) {
      return true;
   } catch (SpecException1 se1) {
      return true;
   ...
   } catch (Exception e) {
      return false;
   }   
}

It depends on how you construct the array of exceptions. If the java 7 stuff works properly then you could put all exceptions in one catch:

boolean offerRetry(Exception exception) {
   try{
      throw exception;
   } catch (SpecException | SpecException1 | ... se) {
      return true;
   } catch (Exception e) {
      return false;
   }   
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!