I have to following exemplary type structure
abstract type bla end
abstract type blup <: bla end
mutable struct Ablup <: blup
a::Real
end
mutable struct Bblup <: blup
b::Real
end
init(obj::bla) = println("bla")
init(obj::blup) = println("blup")
init(obj::Ablup) = println("Ablup")
init(obj::Bblup) = println("Bblup")
testA = Ablup(1)
testB = Bblup(1)
init(testA)
init(testB)
how can I call the bla
and blup
implementation of init
?
E.g. if I want to extend the super type method
Use the invoke
function:
julia> invoke(init, Tuple{bla}, testA)
bla
julia> invoke(init, Tuple{bla}, testB)
bla
julia> invoke(init, Tuple{blup}, testA)
blup
julia> invoke(init, Tuple{blup}, testB)
blup
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