JAVA8新特性

專注的阿熊發表於2021-05-14

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部落格 ” ,連結:http://blog.itpub.net/69946337/viewspace-2772350/,如需轉載,請註明出處,否則將追究法律責任。

相關文章