Java Basics-Four method references

Source: Internet
Author: User

Instance

Direct triangles, which are counted on the third side by both sides, are intended to be used to refer to these methods. The code is a bit more inappropriate, forgive yourself.

static method Reference

The parameter list of the interface is the same as the parameter list of the specific implementation method in the class, and the return value is consistent.

Call

    

Static references
Istaticside staticside = five::getstaticsize;
Staticside.getstaticsize (3, 6);

    

Class is defined in the

  

Static references
public static double getstaticsize (double s,double s2)
{
Return math.sqrt (S*S+S2*S2);
}

Defining interfaces


Interface istaticside{

Double getstaticsize (double s,double S2);
}

Instance reference

The parameter list of the interface is the same as the parameter list of the specific implementation method in the class, and the return value is consistent.

Call

  

Five Five = new Five (3,4);

Instance Reference method
Ilastside Side=five::getthelastside;
SYSTEM.OUT.PRINTLN ("instance reference, result of method third side:" +side.getlastside ());

Class is defined in the

Type reference
Public double getfivelastside (Five f) {
Return math.sqrt (THIS.SIDE1 * this.side1 + this.side1 * this.side1);
}

Defining interfaces

Interface Ilastside {
Double Getlastside ();
}

A method defined in a type reference class has only one parameter, that is, the class of the comparison, that is, the interface defining the second parameter in the interface must be two parameters, the first parameter refers to the class, the second argument refers to the class call of the comparison

Type reference
Ilastfiveside typeside = five::getfivelastside;
SYSTEM.OUT.PRINTLN ("type reference, result of the third side:" +typeside.getlastside (five, five));

Class is defined in the

Type reference
Public double getfivelastside (Five f) {
Return math.sqrt (THIS.SIDE1 * this.side1 + this.side1 * this.side1);
}

Interface definition

Interface Ilastfiveside {

Double Getlastside (Five F, Five F2);

}

Construct references

The reference constructor, by example, is a reference to return an object, and then the object is then called by the corresponding method to execute.

Call

Constructor reference
Igetinstance instace = five::new;
System.out.println ("constructor reference, result of the third side:" +instace.getinstance). Getthelastside ());

Class is defined in the

Constructor reference
Public Five getinstance (double s, double s2) {
return new Five (s, S2);
}

Interface definition

The result interface after receiving the reference
Interface Igetinstance {

Five getinstance (double s, double S2);
}

Something

Just yourself through a simple example summary, if there is no place to hope the Great God gate Jiangshan. I have previously been engaged in. NET development, Java knowledge is indeed insufficient, hope that a lot of understanding, do not want to pit teammates.

Java Basics-Four method references

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.