Understanding UnsupportedOperationException

前端 未结 3 1627
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-13 15:58

I don;t quite understand where I can throw this exception.

For instance, I\'m implementing the Future interface and don\'t want anyone calls t

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-13 16:43

    When you want that the callers of your method to know that the operation is not supported you can throw the UnsupportedOperationException.

    You can check here:

    This exception extends the RuntimeException class and thus, belongs to those exceptions that can be thrown during the operation of the Java Virtual Machine (JVM). It is an unchecked exception and thus, it does not need to be declared in a method’s or a constructor’s throws clause. Moreover, the UnsupportedOperationException exists since the 1.2 version of Java.

提交回复
热议问题