0

I have interface and two enum class:

public interface SortColumnType {
  String getName();
}

public enum OneSortColumnType implements SortColumnType {
  ID("id"),
  NAME("name");

  private final String name;

  @Override
  public String getName() {
    return name;
  }
}

public enum SecondSortColumnType implements SortColumnType {
  ID("id"),
  DATE("date");

  private final String name;

  @Override
  public String getName() {
    return name;
  }
}

And class whit parameter. This class is created ONLY through the constructor without parameters. Enum classes are already inheriting from Enum and cannot inherit from other classes. Enum.valueOf() is not suitable because I cannot pass Class during initialization or other actions. How to make the default value of a field with the ID parameter?

@Setter
@NoArgsConstructor
public class SortColum<T extends SortColumnType> {

  T sortColumn = Enum.valueOf(T.class, "ID"); //Exception

  SortType sortDirection = SortType.ASC;
}

Is it possible somehow through the creation of a common class?

wuttke
  • 73
  • 7

0 Answers0