'incompatib le types: java.lang.String cannot be converted to java.util.List<java.lang.String>

How do i convert this ?

Sort sort = new Sort(Sort.Direction.DESC, MTS_DATE_CREATED_STRING);
private Sort(Sort.Direction direction, List<String> properties) {       
}


Solution 1:[1]

As compiler suggest error implies that the Java compiler is unable to resolve a value assigned to a variable or returned by a method, because its type is incompatible with the one declared on the variable or method and it can not convert String to a List<String> i.e

private Sort(Sort.Direction direction, List<String> properties)

Into

private Sort(Sort.Direction direction, String properties)

Solution 2:[2]

The method accepts a List but you are passing a single String. Wrap that String in a List and it can be passed to the existing method.

Sort sort = new Sort(Sort.Direction.DESC, Arrays.asList(MTS_DATE_CREATED_STRING));

The method in question is private, which implies that you may have control over the class in which it resides. In that case, you may add overloaded versions of the method to accept a single String.

private Sort(Sort.Direction direction, String property) { ... }

And/or a varargs version that accepts any number of Strings without a collection...

private Sort(Sort.Direction direction, String... properties) { ... }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 vsfDawg