Difference between `new` and `new{T}`

I understand new{T}(...) must be used instead of new(...) to define an outer constructor inside struct ... end (to define an outer-only constructor, for example).

However, when defining an inner constructor, is there any difference between new and new{T}? For example, I wonder if there is any difference between the following two:

julia> struct MyType{T}
           x::T
           MyType{T}(x) where {T} = new(x)
       end

and

julia> struct MyType{T}
           x::T
           MyType{T}(x) where {T} = new{T}(x)
       end

One uses new(...) whereas the other uses new{T}(...).

1 Like
expand(
quote
    struct MyType{T}
        x::T
        MyType{T}(x) where {T} = new(x)
    end
end)

and

expand(
quote
    struct MyType{T}
        x::T
        MyType{T}(x) where {T} = new{T}(x)
    end
end)

are the same (apart from line number differences), so I don’t think there’s a difference.

1 Like