Java Reference
In-Depth Information
JDK 8 added another new capability to interface : the ability to define one or more static
methods. Like static methods in a class, a static method defined by an interface can be
called independently of any object. Thus, no implementation of the interface is necessary,
and no instance of the interface is required in order to call a static method. Instead, a static
method is called by specifying the interface name, followed by a period, followed by the
method name. Here is the general form:
InterfaceName . staticMethodName
Notice that this is similar to the way that a static method in a class is called.
The following shows an example of a static method in an interface by adding one to
MyIF , shown earlier. The static method is getUniversalID( ) . It returns zero.
The getUniversalID( ) method can be called, as shown here:
As mentioned, no implementation or instance of MyIF is required to call getUniversalID(
) because it is static .
One last point: static interface methods are not inherited by either an implementing class
or a subinterface.
Search WWH ::




Custom Search