Description
openedon Dec 5, 2016
In the "Inner Constructors" section of the manual, it says:
The default constructor is equivalent to writing your own inner constructor method that takes all of the object’s fields as parameters (constrained to be of the correct type, if the corresponding field has a type), and passes them to new, returning the resulting object
Which I would read to mean that:
type T1
x::Int64
end
would be equivalent to:
type T1
x::Int64
T1(x::Int64) = new(x)
end
But right below it gives the above equivalent example as:
type T1
x::Int64
T1(x) = new(x)
end
Which seems to me to imply that new
calls convert
on the fields, because non-Int64
arguments are convert
ed to Int64
.
In the "Types" section of the manual it says:
Two constructors are generated automatically (these are called default constructors). One accepts any arguments and calls convert() to convert them to the types of the fields, and the other accepts arguments that match the field types exactly.
Which I would read to mean that:
type T1
x::Int64
end
would be equivalent to:
type T1
x::Int64
T1(x::Int64) = new(x)
end
T1(x) = T1(convert(Int64, x))
It seems that these two descriptions of the default constructors (either converting in the outer constructor or converting in new
) would behave identically, but it's confusing that it's described both ways in the manual. Is one of them more correct?