Question: Object creation syntax difference

Question

Object creation syntax difference

Answers 1
Added at 2017-01-02 13:01
Tags
Question

Is there a difference between new ClassName and new ClassName()? Is it only a syntax difference or is there a scala magic happening in the background?

Answers to

Object creation syntax difference

nr: #1 dodano: 2017-01-02 13:01

Only a syntax difference, as far as I know. Example using the scala REPL:

scala> val foo = new scala.collection.mutable.HashMap
foo: scala.collection.mutable.HashMap[Nothing,Nothing] = Map()

scala> val foo = new scala.collection.mutable.HashMap()
foo: scala.collection.mutable.HashMap[Nothing,Nothing] = Map()

I think this is simply an example of the normal behavior in Scala where it is allowed to omit the parenthesis when calling a method without arguments.

Source Show
◀ Wstecz