package com.mayikt.service; import com.mayikt.entity.UserEntity; /** * @ClassName Entity * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com * @Version V1.0 **/ public interface UserInterface { UserEntity getUser(); }
package com.mayikt.entity; /** * @ClassName UserEntity * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com * @Version V1.0 **/ public class UserEntity { private String userName; private int age; public UserEntity() { } public UserEntity(String userName, int age) { this.userName = userName; this.age = age; } public String getUserName() { return userName; } public int getAge() { return age; } @Override public String toString() { return "UserEntity{" + "userName='" + userName + '\'' + ", age=" + age + '}'; } // @Override public int hashCode() { return userName.hashCode(); } public boolean equals(Object obj) { if (obj instanceof UserEntity) return userName.equals(((UserEntity) obj).userName) && age == (((UserEntity) obj).age); else return false; } }
package com.mayikt.method; import com.mayikt.entity.UserEntity; import com.mayikt.service.UserInterface; /** * @ClassName Test014 * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com * @Version V1.0 **/ public class Test014 { public static void main(String[] args) { // UserInterface userInterface = () -> new UserEntity(); // 构造函数引入 函数接口返回类型 UserEntity::new.----默认的情况下执行无参构造函数 UserInterface userInterface3 = UserEntity::new; System.out.println(userInterface3.getUser()); } }