keytype
keytype(type)
Get the key type of an associative collection type. Behaves similarly to eltype
.
Examples
julia> keytype(Dict{String, Int})
String
This example demonstrates the usage of keytype
to retrieve the key type of a Dict
associative collection type. The keytype
function returns the key type of the collection.
julia> keytype(Set{Float64})
Float64
In this example, keytype
is used to obtain the key type of a Set
collection, which is Float64
.
julia> keytype(Tuple{Symbol, Int})
Symbol
Here, keytype
is applied to a Tuple
collection type, and it returns the key type as Symbol
.
Common mistake example:
julia> keytype(Vector{Int})
ERROR: MethodError: no method matching keytype(::Type{Array{Int64,1}})
In this example, keytype
is mistakenly used on an array type, which results in an error. keytype
is specifically used for associative collections and not arrays.
See Also
BigFloat, BigInt, Dict, eltype, fieldtype, Float32, Float64, IntSet, isa, isalnum, isalpha, isascii, iseltype, isequal, isgraph, isimmutable, isinteractive, isleaftype, isnull, ispunct, isspace, issubtype, keytype, Nullable, NullException, promote_type, typeintersect, typejoin, typemax, typemin, typeof, Val, valtype,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.