If you want, you can write

type AA
  aa
  bb

  function AA()
    this = new()
    this.aa = 1
    this.bb = 2
    this
  end
end

But that seems like a lot more typing and constructing incomplete objects 
gratuitously is a bad idea, so I wouldn't recommend it.

> On May 10, 2014, at 12:12 AM, "Steven G. Johnson" <[email protected]> 
> wrote:
> 
> 
> 
>> On Friday, May 9, 2014 8:28:45 PM UTC-4, K leo wrote:
>> I meant having the inner constructor but having no need to write the new 
>> statement.  Isn't the purpose of the new statement implied by the 
>> constructor already?
> 
> No, because the variables "aa" and "bb" in your constructor are simply local 
> variables of your constructor function, and don't necessarily have anything 
> to do with the fields of the object being constructed.   For example, it 
> would be perfectly valid to do:
> 
> type AA 
>      aa 
>      bb 
> 
>      function AA() 
>          aa=1 
>          bb=2 
>          new(bb,aa) 
>      end 
> end 
> 
> I think you're getting confused by comparison to traditional OO languages 
> where methods are "owned" by the type and fields of the type are 
> automatically local variables of the type's methods.   That's not the case in 
> Julia.

Reply via email to