On Jan 29, 2019, at 11:10 AM, Remi Forax <fo...@univ-mlv.fr> wrote: > > currently the result of the expression "new Object()" is a reference type, so > it should be a RefObject, but we have created an Object not a RefObject, > so it's at best weird.
I'd like to rationalize this in two steps. First, allow `new I(x…)` where `I` is an interface, to be treated as shorthand for `I.F(x…)` where the method `F` is somehow declared by `I` as its canonical factory. I'm thinking `List.of` is a good one. (Maybe also extend this rule to classes with non-public constructors.) Second, since `Object` is an honorary interface, change the meaning of `new Object()` to be `Object.newReference()` (or some such), by having `Object` declare `newReference` (of no arguments) as its canonical factory. Moving `new` statements to factories is coherent, also, with changing the translation strategy for Java to deprecate the new/init dance outside of the class being constructed, and eventually make it illegal in bytecode outside of the nest of the class being made. In other words, if I could go back in a time machine and rewrite the translation strategy, I'd insist that each class (or the JVM itself) would define a canonical factory for each constructor of that class, and require all other classes to allocate via the canonical factory. The new/init dance would be legal inside the class but nowhere else. That attack surface has been a painful one. And value types have to use factories from the get-go, so we've got to figure it out sooner or later. The name of the canonical factory can be, in fact, fixed as '<init>'. — John