Interface for Java

Source: Internet
Author: User

1. What is an interface

(1) The interface is a collection of some method features, which are public by default, and properties can be modified with public static final.

(2) An interface can be considered as the secondary type of an object, and the parent class of the object is the primary type. For example, the main type of TreeMap is Abstractmap, followed by clonable and serializable

(3) The interface is a commitment to the customer, once made, cannot be withdrawn.

2. Why to use the interface

(1) Avoid hardcode dependent on another object, dynamically relying on another object.

(2) The guarantee of the pluggable nature

A. The relevance of the pluggable nature. A class is associated with another class, and only its interfaces need to be associated

B. The pluggable nature of the call. One object invokes another object's method

3. Common usage of interfaces

(1) Single-method interface: A method pointer similar to C. such as the Runnale interface

(2) Identity interface: an interface that does not have any properties and methods, such as serializable,java.rmi.remote, that tightly identifies the object as having a type

(3) Constant interface: You can declare some constants in the interface with public static final. This does not have to declare them again in the "inheriting" class. These classes are used like they do with their own constants, rather than having to define them over and over.

(4) Generalized interface

Interface for Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.