My codes are here. My puzzle is in the main method of Test.java, the first case prints the result using its implementation, while another as a normal lambda expression prints what it actually is. Also I wanna know if they have the same method signature causing the problem.
public class Test {
public static void main(String[] args) {
Function<ApplyService, Class<? extends ApplyService>> f1 = ApplyService::run;
System.out.println(f1.apply(new ApplyService1()));
// class Function.ApplyService1 - It's strange, got a result with 'ApplyService1.run'
//
Function<ApplyService, Class<? extends ApplyService>> f2 = Abc::run2;
System.out.println(f2.apply(new ApplyService1())); // null as wish
}
}
interface Abc {
static Class<? extends ApplyService> run2(ApplyService app) {
return null;
}
}
interface ApplyService {
default Class<? extends ApplyService> run() {
return null;
}
}
class ApplyService1 implements ApplyService{
public Class< ? extends ApplyService> run(){
return this.getClass();
}
}