Problem : Create a standalone jar executable which will print the list of candidates appearing for the interview sorted order by name, age and experience ascending.

We getting compilation error -

Employee Class

package com.example.demo.employee;

public class Employee implements Comparable<Employee> {

private String name;
private int age;
private int exp;

public Employee(String name, int age, int exp) {
    super();
    this.name = name;
    this.age = age;
    this.exp = exp;
}

public Employee() {
}

// getter setter

@Override
    public int compareTo(Employee emp) {
    //replace your comparator here
       return (this.getAge() - emp.getAge());
  }
 }

}

Employee Service Class

package com.example.demo.employee;

import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeService {


public List<Employee> getEmployees() {

    Employee e1 = new Employee("Sandhya", 20, 0);
    Employee e2 = new Employee("Kemp", 24, 2);
    Employee e3 = new Employee("Anil", 22, 3);
    Employee e4 = new Employee("Kumar", 30, 6);
    Employee e5 = new Employee("Tim", 32, 7);

public List<Employee> getEmployees() {

    List<Employee> eList = new ArrayList<>();
    eList.add(e1);
    eList.add(e2);
    eList.add(e3);
    eList.add(e4);
    eList.add(e5);

    Collections.sort(eList);

    return eList;
  }
}

EmployeeController

package com.example.demo.employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class EmployeeController {

@Autowired
EmployeeService es;

@RequestMapping(value = "/")
public List<Employee> getEmpList(){
    List<Employee> list = es.getEmployees();
    return list;
  }
}

Error detail are -

[INFO] -------------------------------------------------------------

[ERROR] COMPILATION ERROR : 

[INFO] -------------------------------------------------------------

[ERROR] /projects/challenge/src/main/java/com/example/demo/employee/Employee.java:[45,1] class, interface, or enum expected

[INFO] 1 error

[INFO] -------------------------------------------------------------

[INFO] ------------------------------------------------------------------------

[INFO] BUILD FAILURE

[INFO] ------------------------------------------------------------------------

Comment From: ddr34

This is code issue and not spring boot issue.