3 ms·
What did you expect it to print, and why, if I may ask?
by x3ro 13y ago
What did you expect it to print, and why, if I may ask?
- lmm 13y agoI expected it to print "B", because D is visually closer to B so it would make more sense to me for it to be biased in that direction. (I was quite conscious that I was guessing, and wouldn't have written code depending on my assumption without testing it first)
- harlock81 13y agoThe behavior you get is because of class linearization: this article explains it quite clearly: https://code.google.com/p/scala-discovery/wiki/Linearization https://code.google.com/p/scala-discovery/wiki/Linearization
- x3ro 13y agoI'm not quite sure what you mean by "visually" closer. Do you mean the actual distance in characters between "class D" and "with B"? Intuitively, I expected the compiler to first add the "B" trait, and then the "C" trait, which overwrites what was previously added by the "B" trait. But this seems to be much more subjective that I would've thought, apparently ;)
- lmm 13y ago>Do you mean the actual distance in characters between "class D" and "with B"? Yes, exactly that.