Skip to content

Commit aa2421d

Browse files
Documentation: added example to the function hasfield. (From #41782) (#44274)
Co-authored-by: Johnny Chen <[email protected]> (cherry picked from commit 9c0e5b0d186ea95a06d5b0bdc4bc19d1a17b444d)
1 parent 0db596e commit aa2421d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

base/reflection.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,23 @@ fieldnames(t::Type{<:Tuple}) = ntuple(identity, fieldcount(t))
194194
195195
Return a boolean indicating whether `T` has `name` as one of its own fields.
196196
197+
See also [`fieldnames`](@ref), [`fieldcount`](@ref), [`hasproperty`](@ref).
198+
197199
!!! compat "Julia 1.2"
198200
This function requires at least Julia 1.2.
201+
202+
# Examples
203+
```jldoctest
204+
julia> struct Foo
205+
bar::Int
206+
end
207+
208+
julia> hasfield(Foo, :bar)
209+
true
210+
211+
julia> hasfield(Foo, :x)
212+
false
213+
```
199214
"""
200215
function hasfield(T::Type, name::Symbol)
201216
@_pure_meta

0 commit comments

Comments
 (0)