引用静态方法
...
ackage edu.xcdq;
interface IMyMessage<P,R>{
R int2String(P zhengshu);
}
public class Demo04 {
public static void main(String[] args) {
IMyMessage<Integer,String>shili = String::valueOf;
String str = shili.int2String(50000);
System.out.println(str.length());
}
}
...
引用某个对象的方法
...
package edu.xcdq;
//引用 对性的方法
interface IMyMessage1<R>{
R zhuandaxie();
}
public class Demo05 {
public static void main(String[] args) {
IMyMessage1<String> shili = "hello "::toUpperCase;
System.out.println(shili.zhuandaxie());
}
}
...
引用某个特定类的方法
...
package edu.xcdq;
interface IMyMessage6<R,P>{
R compare(P p1, P p2);
}
public class Demo06 {
public static void main(String[] args) {
IMyMessage6<Integer,String>message6 = String::compareTo;
System.out.println(message6.compare("侯","姚"));
}
}
...
引用构造方法
...
package edu.xcdq;
//引用构造方法 Student::new
interface IMyPerson<R,PN,PA>{
R message(PN name,PA age);
}
public class Demo07 {
public static void main(String[] args) {
IMyPerson<Student,String,Integer>shili = Student::new;
System.out.println(shili.message("Jackma",50));
}
}
...