#2154 Static New?

SlimerDude Mon 3 Jun 2013

I was under the impression that fromStr() methods were static factory methods because, by convention, all ctors are prefixed with make.

Then I discover sys::Int.fromStr which is not only static, but static new! Woah! How does that work?

So I guess I have 2 questions:

  1. What is static new? (Or are all ctors implicitly static?)
  2. Is it correct to have ctors prefixed with from and not make. (If so, what is the naming convention for ctors and static factory methods?)

I ask because I'm using reflection to look up fromStr() and want to know if I should be checking the Method.isCtor value.

andy Mon 3 Jun 2013

Think this was the last discussion on this #1776 - but details:

They would work just like any static method, but with a few special aspects:

1. They are implied to return declaring class, in case above it is implied to return Foo?

2. According to existing rules, methods flagged with new keyword are not inherited into subclass namespace. So they will not conflict with methods in subclass namespace. This solves a lot problems people are having with factory methods on base classes and mixins.

3. Any method flagged with new (either static or instance) gets to take advantage of shortcut syntax. We now have a way to know that a given method is intended to be used for construction

Login or Signup to reply.