Type introspection and reflection capabilities
Type introspection and reflection capabilities form a very useful part of any modern-day programming language. Their need arises due to the fact that many a time while coding, we come across a situation where we need to understand the types of objects or data that we are dealing with. Sometimes, we may need to find the type of an object, and other times we may end up coding some logic based on that object's types and properties.
Type introspection
As we know from the starting chapters that Julia supports multiple dispatch and we can create a new data type from any abstract data type, let's define a new type, named Student
, and then create two sample objects for this type:
julia> type Student
name::String
age::Int64
end
julia> alpha = Student("alpha",24)
Student("alpha", 24)
julia> beta = Student("beta",25)
Student("beta", 25)
Pretty simple! Now that we have two of these students, with the names alpha
and beta...