Understanding UnsupportedOperationException

前端 未结 3 1624
爱一瞬间的悲伤
爱一瞬间的悲伤 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:27

    Yes, you are right.

    The author of UnsupportedException is Joshua Bloch and as per his book and also from Collections design FAQ, if the object does not support an operation, the method can throw UnsupportedException.

    Caution should be taken before throwing this exception in your method because, it is of type RuntimeException/unchecked exception.

    Link to the book

    Author of the book and UnsupportedException class : Joshua Bloch

    /**
     * Thrown to indicate that the requested operation is not supported.

    * * This class is a member of the * * Java Collections Framework. * * @author Josh Bloch * @version %I%, %G% * @since 1.2 */ public class UnsupportedOperationException extends RuntimeException { ... }

提交回复
热议问题