Andrew
03/05/2021, 10:26 AMfun Int.toFriendlyName(): String{
return when(this) {
PredefinedValue1 -> "PredefinedValue1"
PredefinedValue2 -> "PredefinedValue2"
PredefinedValue3 -> "PredefinedValue3"
else -> willNeverHappen("This value is not supported")
}
}
However this is problematic as this extension function can now be used on all integers in the scope of the extension functions.
I know that the `Int`s that I will be calling this on will be annotated with @Barcode.BarcodeFormat - so is there a way for me to mark that on my extension function so that I can only use it on integers with that specific annotation?Roukanken
03/05/2021, 10:43 AMAndrew
03/05/2021, 10:45 AMAndrew
03/05/2021, 11:47 AMJoel
03/05/2021, 3:01 PMInt
, but it really must be imported first, which allows you to limit the blast radius. Honestly I'd say this is working as expected. You could put the extension function inside of an object so you can make the context more specific if desired:
object BarCodeHelper {
fun Int.toFriendlyName() = ...
}
with(BarCodeHelper) {
someInt.toFriendlyName()
}
araqnid
03/05/2021, 3:45 PMinline class
that defines the method - thatās the way to distinguish āspecialā numbers/strings etc that have additional behaviour attached to themRoukanken
03/05/2021, 4:00 PMRoukanken
03/05/2021, 4:02 PMRoukanken
03/05/2021, 4:04 PMAndrew
03/05/2021, 4:58 PMaraqnid
03/05/2021, 5:23 PMRoukanken
03/06/2021, 4:26 PM