I have this method.
private fun getOffer(offers: OfferRepresentation, type: OfferType): ???? {
return when (type) {
OfferType.ADDON -> offers.addon
OfferType.SALE -> offers.sale
OfferType.PLAN -> offers.plan
OfferType.CUSTOMPLAN -> offers.customPlan
}
How can i change this method to return the correct type?
It's hard to give you a difinitive answer without you giving more info, but the easiest way to return multiple types is to have them all share an interface or superclass:
interface Offer
class Addon : Offer
class Sale : Offer
class Plan : Offer
class CustomPlan : Offer
You can also use a sealed class
if your options are static, it just depends on your use case. Either way, you can then just have the function return type be Offer
For more information see:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With