tylerwilson
05/10/2018, 2:25 PMdata class Item<T>(val operand1: T, val operand2: T) {
val result: T = operand1 / operand2
}
But it gives me errors about BigDecimal (I guess this is the first class it tried to match. So I need to constrain T to be only types that support division, like T: Number, T: divideBy or something. Is this possible in Kotlin? Thank you!Andreas Sinz
05/10/2018, 2:37 PMInt
, Float
etc. implementsAndreas Sinz
05/10/2018, 2:37 PMdata class Item<T>(val operand1: T, val operand2: T, val operation: (T, T) -> T) {
val result: T = operation(operand1, operand2)
}
tylerwilson
05/10/2018, 2:39 PMAndreas Sinz
05/10/2018, 2:40 PMtylerwilson
05/10/2018, 2:41 PMAndreas Sinz
05/10/2018, 2:42 PM