// Changed EmployeeServive to return an optional, no more nulls! Optional<Employee> employee = employeeServive.getEmployee(); employee.ifPresent(e -> System.out.println(e.getId()));