标题:java8新特性构造器引用问题
只看楼主
持剑的战士
Rank: 1
等 级:新手上路
帖 子:30
专家分:3
注 册:2019-12-6
结帖率:62.5%
 问题点数:0 回复次数:0 
java8新特性构造器引用问题
public class Employee {
    int id;
    String name;
    int age;
    double salary;

    public Employee() {
    }

    public Employee(int id) {
        this.id = id;
    }

    public Employee(int id, String name, int age, double salary) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.salary = salary;
    }
}

@Test
    public void test1(){
        Supplier<Employee> sup1 = () -> new Employee();
        System.out.println(sup1.get());

        System.out.println("****************************");

        Supplier<Employee> sup2 = Employee::new;
        System.out.println(sup2.get());
    }

调试结果是:
com.nuist.java2.Employee@649d209a
****************************
com.nuist.java2.Employee@357246de

为什么不是:
Employee{id=0,name='null',age=0,salary=0.0}
请问是哪里出问题了?急急急
搜索更多相关主题的帖子: this Employee age name int 
2021-05-18 22:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-505778-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015900 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved