Is it possible to inherit from something other than the abstract type julia?


I have a function that I can’t change and it expects type ExpectedType.

function some_function(some_parameter::ExpectedType)
   some implementation

I want to pass my object of type OtherType.

I decided to inherit OtherType from ExpectedType.

struct OtherType <: ExpectedType end

But I’m getting an error: ERROR: invalid subtyping in definition of OtherType

  1. Is it possible to inherit from non-abst types?
  2. How can I get the functionality I need?

>Solution :

  1. It is not possible to inherit from non-abstract type.
  2. What I would typically do is writing a constructor for ExpectedType that takes OtherType as argument and then call some_function(ExpectedType(your_object)).

Leave a Reply Cancel reply