JDK 8 introduced the possibility of defining static methods in interfaces.
Static methods in interfaces can be called independently of any object, similar to static methods in classes.
An implementation or interface instance is not required to call a static method.
The syntax for calling a static method of an interface is: InterfaceName.StaticMethodName.
The operation is similar to static methods of a class.
Example: in the MyIF interface, the static getUniversalID() method was added, returning the value zero.
The getUniversalID() method can be called like this: int uID = MyIF.getUniversalID().
An implementation or instance of MyIF is not required to call getUniversalID(), as it is a static method.
Static interface methods are not inherited by implementing classes or subinterfaces.
The above is the detailed content of Use static methods in an interface. For more information, please follow other related articles on the PHP Chinese website!