I want to refer a field name in one class of java to another, such that I would get at least compiler error when someone changes the field name in base class.
Ex:
@Entity
class Employee {
    public String userId;
    public String timestampCreate;
}
class EmployeeReport {
    public Page<Employee> getEmployees() {
        return page = employeeJpaRepository.findAll(pageNumber, pageSize,
                Sort.by(Sort.Direction.DESC, "timestampCreate"));
    }
}
Here timestampCreate is the field name of Employee class.
I do not want to hardcode the column name; as it is bad practice and want it to be future proof, in case the field name changes. i.e. for example if someone changes the column name 'timestampCreate' to 'timestamp', then at lease I would like to see some compiler error in the EmployeeReport class.
Please suggest an idea. Thanks!
Note: My question is nowhere answered by the question they mapped and marked duplicate! I don't know why it was marked as duplicate and how to remove that!
