Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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
   ....
end

I want to pass my object of type OtherType.

I decided to inherit OtherType from ExpectedType.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)).
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading