But if I am to instantiate it normally a =Foo(12), it continues and
completes without me defining a convert method. What is really happening
here?
Thanks
On Monday, January 4, 2016 at 10:53:54 AM UTC-8, Julia Tylors wrote:
>
> I have a question about the convert method, Look at the example below, It
> tells me to define convert method here.
> Thanks
>
> julia> type Foo{T}
> x::T
> end
>
> julia> a = convert(Foo{Int64},12)
> ERROR: MethodError: `convert` has no method matching
> convert(::Type{Foo{Int64}}, ::Int64)
> This may have arisen from a call to the constructor Foo{Int64}(...),
> since type constructors fall back to convert methods.
> Closest candidates are:
> Foo{T}(::Any)
> call{T}(::Type{T}, ::Any)
> convert{T}(::Type{T}, ::T)
>
>
> But if I am to instantiate it normally a =Foo(12), it doesn't complete.
> And it calls some convert method which does the conversion right? How is
> this happening?
>
> Thanks
>