Gustav Elmgren
05/29/2023, 12:56 PMval price = double("price")
in a table object. And then I do something like:
val test = TableObj.price.avg()
Should test
not be assignable to Function<BigDecimal>
? Given it's type is Avg<Double, Double>
and Avg
implements Function
?
fun <T : Comparable<T>, S : T?> ExpressionWithColumnType<in S>.avg(scale: Int = 2): Avg<T, S> = Avg<T, S>(this, scale)
class Avg<T : Comparable<T>, in S : T?>(
/** Returns the expression from which the average is calculated. */
val expr: Expression<in S>,
scale: Int
) : Function<BigDecimal?>(DecimalColumnType(Int.MAX_VALUE, scale)) {
override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit = queryBuilder { append("AVG(", expr, ")") }
}
Chantal Loncle
05/30/2023, 2:19 AMAvg()
extending the abstract class Function
means any of the following works:
val test1: Avg<Double, Double> = TableObj.price.avg()
val test2: Function<BigDecimal?> = TableObj.price.avg()
val test3 = TableObj.price.avg() as Function<BigDecimal?>
But Function<BigDecimal?>
would be required, with a nullable type argument.