Optional Method

A method of a Java interface can be optional. This means that a class that implements the interface may not implement the body of the method but simply throw a java.lang.UnsupportedOperationException.

A class must clearly state which methods are optional and under what conditions they will throw an UnsupportedOperationException. A method is considered optional if it may under any circumstances throw that exception.

Put another way, optionality is always a static property of a method of a concrete class. But optional methods may be dynamically enabled, disabled and re-enabled but the method is still considered optional. That means it is the programmer's responsibility to manage the dynamic aspect of optionality.

For example, a class may implement Freezable or Thawable, which provide methods freeze() and thaw() respectively (see package com.steelypip.powerups.common).