I am trying to create a class implementing comparable. When all the class elements are integer, everything works well. When I go with String and use comparing rather than comparingInt, I receive the following errors.
Incorrect number of type arguments for generic method comparing(Function) of type Comparator; it cannot be parameterized with arguments
The type myClassdoes not define getFrom(T) that is applicable here
public class myClass implements Comparable<myClass> {
@Column (name="From")
private String from;
@Column (name="To")
private String to;
@Column (name="With")
private String with;
@Column (name="amount")
private int amount;
// Setters, getters, constructor
Comparator<myClass > comp = Comparator.<myClass>comparing(myClass::getFrom)
.thenComparing(myClass::getTo)
.thenComparing(myClass::getWith)
.thenComparingInt(myClass::getAmount);
@Override
public int compareTo(myClass o) {
return comp.compare(this, o);
}
}
Could someone point out what I might be missing here?
Comparator.<myClass, String>comparing...