Hey guys. Dunno if I'm just stupid. But lets say i...
# exposed
g
Hey guys. Dunno if I'm just stupid. But lets say i have a
val price = double("price")
in a table object. And then I do something like:
Copy code
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
?
Copy code
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, ")") }
}
c
You're correct in that
Avg()
extending the abstract class
Function
means any of the following works:
Copy code
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.