This chapter covers
- Understanding type hierarchies
- Differences between abstract and concrete types
- Combining primitive types to make composite types
- Harnessing the power of multiple dispatch to solve complex tasks elegantly
- How multiple dispatch differs from single dispatch in object-oriented languages1
All objects in Julia are of a particular type. Remember, you can use typeof to discover the type of any object:
julia> typeof(42) Int64 julia> typeof('A') Char julia> typeof("hello") String
The type decides what you can do with an object. For example, a dictionary allows you to look up a value by key, while an array stores elements in order. An expression evaluating to a Bool value, such as true or false, can be used in an if statement and while loops, while expressions evaluating to a floating-point value can’t:
julia> if 2.5 print("this should not be possible") end ERROR: TypeError: non-boolean (Float64) used in boolean context