Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a super type method?

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

like image 918
OhmSweetOhm Avatar asked Jan 26 '23 02:01

OhmSweetOhm


1 Answers

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
like image 192
Bogumił Kamiński Avatar answered Jan 30 '23 01:01

Bogumił Kamiński