Home > Java > javaTutorial > Use static methods in an interface

Use static methods in an interface

Linda Hamilton
Release: 2024-10-09 06:10:02
Original
1101 people have browsed it
  • 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.

Use métodos static em uma interface

  • 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!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template