Julia: OOP or not

When in doubt, read the documentation…

https://docs.julialang.org/en/v1/manual/types/#Composite-Types-1

Long story short:

struct MyType
    a::Int64
    b::Float64
end

x = MyType(3, 4)

x.a

EDIT: Methods are defined outside the type definition, e.g.

function double(x::MyType)
    x.a *= 2
end

Methods do not live inside the type, as they would do in C++ or Python, for example. This allows one of the key features of Julia, multiple dispatch, to work also with user-defined types, which are on exactly the same level as system-defined types.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)