https://kotlinlang.org logo
Title
h

Hullaballoonatic

05/03/2019, 11:56 PM
can i overload
Double::div
? i'd like for it to return
0.0
when dividing by
0.0
in this scope
n

nfrankel

05/04/2019, 12:13 AM
you could create a
safeDiv
method without the benefit of an operator
h

Hullaballoonatic

05/04/2019, 12:14 AM
yeah, i can, but it's a shame i can't just overload it
n

nfrankel

05/04/2019, 12:17 AM
overloading means subclassing
h

Hullaballoonatic

05/04/2019, 12:45 AM
what's the term for overriding a function in a scope, then?
just overriding?
n

nfrankel

05/04/2019, 3:13 AM
sorry, i meant overriding the first time overriding means a parent-child relationship and the child overrides the behavior of the parent that’s what you want: you have a class
Double
a function
div()
and you want to change its behavior this is not possible... unless you create your own subclass of
Double
and it’s final
k

karelpeeters

05/04/2019, 6:43 AM
That would be called shadowing but it's not possible: https://kotlinlang.org/docs/reference/extensions.html#extensions-are-resolved-statically
👍 1