25

If I have DerivedType1:BaseType and DerivedType2:BaseType and Array[DerivedType1] and Array[DerivedType2], what's the most succinct way of combining them into Array[BaseType]?

1
  • 5
    C++ background? Don't use X:Y to denote inheritance, because that's the syntax for context bound. Commented Oct 24, 2011 at 16:05

1 Answer 1

40

Use the ++ method on Array.

scala> class A; class B extends A; class C extends A
defined class A
defined class B
defined class C

scala> Array(new B, new B) ++ Array(new C, new C)
res33: Array[A] = Array(B@b7501b, B@ec5359, C@1540d0c, C@124a927)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.