1

I've searched around for a long time now and haven't come up with any official reason why scala doesn't support multiple inheritance. I know traits solve a lot of things, but the developers of C# for example give an explicit reason why not to implement it (link here).

Any pointers?

closed as unclear what you're asking by gnat, user40980, user53019, Kilian Foth, Mark Booth Jan 6 '15 at 17:49

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

4

One of Scala's primary design goals is to interoperate with Java as smoothly as possible. In order to achieve this, a Scala class must have a one-to-one correspondence with a JVM class. Because the JVM ddoesn't support multiple inheritance, it would therefore be impossible for Scala to do so without introducing massive hacks.

  • 1
    Source for your statement ”the JVM doesn't support multiple inheritance”: the JVM Spec, section 4.1 “The ClassFile Structure” states that class descriptions contain a single super_class field that can either be empty or reference a superclass, whereas classes can reference any number of interfaces. – amon Jan 3 '15 at 12:20
3

Scala does support Multiple Inheritance: you can inherit from as many traits as you want.

So, the reason for why there is no official documentation for the reasons for not supporting MI is simply that there aren't any, because Scala does support MI. You say "traits solve a lot of things", and MI is one of them.

  • 3
    Yes, any class or trait may inherit from multiple traits. But for some reason, you can't inherit from more than one class. Why and how are traits and classes different? Why this restriction on class inheritance? I do not believe this post answers the question. – amon Jan 3 '15 at 9:29
  • per my reading of the question, asker appears to be already aware of that: "I know traits solve a lot of things" (in the light of this, concern raised by @amon seems to make much sense) – gnat Jan 3 '15 at 10:40
  • 2
    @gnat: the OP says "I know traits solve a lot of things", but he doesn't elaborate on what those "lot os things" and what is missing from those "lot of things". His main point seems to be that there is no official documentation for the absence of MI, and the reason why there is no official documentation for the absence of MI is that there is no absence of MI. – Jörg W Mittag Jan 3 '15 at 12:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.