Missing support for writing generic-less code


#1

Now this may sound ridiculous. Why would one want to use e.g. List instead of List<String>? Please let me explain.
I am trying to call the JPA API CriteriaBuilder.greaterThanOrEqualTo, which has the following signature:

<Y extends Comparable<? super Y>> Predicate greaterThanOrEqualTo(Expression<? extends Y> x, Y y);

However, the value of Y is computed dynamically, based on the Class of the target field. Generally, one may use java.util.Date but has to use LocalDate when the JPA field is of type LocalDate, not important. I have a function returning Comparable<*> since there is no other supertype of Date and LocalDate than Comparable.

And here’s the issue: I can’t find a way to cast Comparable<*> to Comparable<Y>. In Java, one can cast to Comparable and suppress the warnings, yet in Kotlin I can’t do that. What should I do? Thanks! :slight_smile:


#2

Currently “solved” this by moving the greaterThanOrEqualTo code to the function, which then returns something else. In particular:
https://github.com/mvysny/vaadin-on-kotlin/blob/vaadin8experiment/vok-framework/src/main/java/com/github/vok/framework/vaadin/VaadinFilters.kt#L258

Before, the toFilter() function returned Comparable<*>, now it directly returns JPAFilter.