I withdraw my previous Pre-SIP proposal. It has a fatal flaw that was overlooked by my reasoning with analogy (which is always dangerous!). The flaw is in this part:
The generation of an
apply
method is suppressed if that method would clash with anapply
method already given in that companion object. The meaning of “clash” is the criterion that currently determines whether anapply
method for a case class should be generated.
This works fine for case classes, but breaks down for normal classes. Why? Consider an idealized Array
class:
class Array[T](length: Int)
object Array {
def apply[T](xs: T*): Array[T] = ...
}
Under my previous proposal, Array(10)
would again produce an uninitialized array of length 10 instead of an array of length one with element 10. So this would change the semantics of existing
programs.
The same rule works OK for case classes because we have always generated an apply
method for them.
I’ll post in the next comment a new pre-SIP proposal that implements function call syntax for instance creations in a different way. I leave aside for the moment the part dealing with how to replace new
expressions