On 10/6/14, 3:06 PM, "OmPrakash Muppirala" <bigosma...@gmail.com> wrote:

>On Mon, Oct 6, 2014 at 2:57 PM, Alex Harui <aha...@adobe.com> wrote:
>>Similarly, are there any AS Singleton patterns that are sufficient?  Such
>> as:
>>
>> public class MySingleton
>> {
>>     public function MySingleton(secretToken:SecretToken)
>>     {
>>     }
>> }
>> internal class SecretToken
>> {
>> }
>>
>
>This partially works.  I can still do:
>
>var instance:MySingleton = new MySingleton(null);
>
>I now need to add a null check in MySingleton's constructor and throw a
>runtime error if secretToken is null.
>
>Whereas, if private constructor is supported, this would be caught in
>compile time.
I don¹t doubt that private constructors would be preferred, but if the VM
isn¹t going to help us, and potentially, the ABC format may make it
impossible/difficult/expensive to make it work, what trade-offs would we
make or what other ideas would work?

Could we teach the compiler that certain parameters cannot be assigned
null?  JavaScript seems to have something like that.

Could the compiler just check an ASDoc annotation and detect an attempt to
instantiate from outside the class?

-Alex

Reply via email to