1

I see this syntax in scala. val variable = new SomeClass("arguments") {...}. Why is there a body after new and how's it different from the java way of creating an object

1
  • Normally it is used to instantiate a trait, content in {...} will implement or override methods or val of that trait, same if SomeClass is a class. Commented May 5, 2016 at 8:09

1 Answer 1

5

That's no just a instance of SomeClass, it's also an extension of that class. This syntax creates a anonymous subclass of SomeClass and instantiate the new subclass.

I don't think your question, as is, has anything to do with class initialization.

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.