I would like to achieve something where I could call a data class with either an Int or BigDecimal type. So for example:
data class Money(val amount: Int, val currencyCode: CurrencyCode) {
fun toSmallestUnit(): Int = when (this.currencyCode) {
CurrencyCode.USD -> this.amount * 100
CurrencyCode.EUR -> this.amount * 100
}
}
Here I would like to be able to send both Int and BigDecimal as an amount to data class Money, and then have different toSmallestUnit function for each type. How can I achieve this in Kotlin?