I am confusing with when constructing a 1-d array of the specified type by usung getindex(type[, elements...]).
Of course, that I can convert Int 8 when the element are Int
getindex(Int8, 1, 2)
2-element Vector{Int8}:
1
2
Even when the element are character format, I can convert it to Int8 :
getindex(Int8, '1', '2')
2-element Vector{Int8}:
49
50
However, I can not convert when the element are in string format.
getindex(Int8, "1", "2")
and, raise the following error :
MethodError: Cannot `convert` an object of type String to an object of type Int8
Closest candidates are:
convert(::Type{T}, ::Ptr) where T<:Integer at pointer.jl:23
convert(::Type{IT}, ::GeometryBasics.OffsetInteger) where IT<:Integer at C:\Users\Admin\.julia\packages\GeometryBasics\WMp6v\src\offsetintegers.jl:40
convert(::Type{T}, ::SentinelArrays.ChainedVectorIndex) where T<:Union{Signed, Unsigned} at C:\Users\CARVI\.julia\packages\SentinelArrays\tV9lH\src\chainedvector.jl:209
...
Stacktrace:
[1] setindex!(A::Vector{Int8}, x::String, i1::Int64)
@ Base .\array.jl:839
[2] getindex(#unused#::Type{Int8}, x::String, y::String)
@ Base .\array.jl:393
[3] top-level scope
@ In[35]:1
[4] eval
@ .\boot.jl:360 [inlined]
[5] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1116
Why getindex() allow character element to convert to different format (like character -> Int8), but string ?