ITPub博客

首页 > IT职业 > IT生活 > Java8新特性

Java8新特性

IT生活 作者:专注的阿熊 时间:2021-05-14 16:23:52 0 删除 编辑

Lambda 是一个匿名函数,我们可以把 Lambda 表达式理解为是一段可以传递的代码(将代码像数据一样进行传递)。可以写出更简洁、更灵活的代码。作为一种更紧凑的代码风格,使 Java 的语言表达能力得到了提升。

package day01.com.lm.java8;

import java.util.Objects;

public class Employee {

     private int id;

     private String name;

     private Integer age;

     private double salary;

     private Status status;

     public Employee(String name, Integer age, double salary, Status status) {

         this.name = name;

         this.age = age;

         this.salary = salary;

         this.status = status;

     }

     public Employee() {

         super();

     }

     public Employee(int id) {

         this.id = id;

     }

     public Employee(String name, Integer age, double salary) {

         this.name = name;

         this.age = age;

         this.salary = salary;

     }

     public String getName() {

         return name;

     }

     public void setName(String name) {

         this.name = name;

     }

     public Integer getAge() {

         return age;

     }

     public void setAge(Integer age) {

         this.age = age;

     }

     public double getSalary() {

         return salary;

     }

     public void setSalary(double salary) {

         this.salary = salary;

     }

     public Status getStatus() {

         return status;

     }

     public void setStatus(Status status) {

         this.status = status;

     }

     @Override

     public String toString() {

         return "Employee{" +

                 "id=" + id +

                 ", name='" + name + '\'' +

                 ", age=" + age +

                 ", salary=" + salary +

                 ", status=" + status +

                 '}';

     }

     @Override

     public boolean equals(Object o) {

         if (this == o) return true;

         if (o == null || getClass() != 外汇跟单gendan5.como.getClass()) return false;

         Employee employee = (Employee) o;

         return id == employee.id &&

                 age == employee.age &&

                 Double.compare(employee.salary, salary) == 0 &&

                 Objects.equals(name, employee.name);

     }

     @Override

     public int hashCode() {

         return Objects.hash(id, name, age, salary);

     }

     public enum Status {

         FREE,

         BUSY,

         VOCATION

     }

}


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69946337/viewspace-2772350/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-23

  • 博文量
    410
  • 访问量
    276818