Type Annotations in Julia
Julia is a dynamically typed language i.e. the type of the variable need not be declared in the program statically. Along with this, it also provides a technique to comment on the type of variable to the Just-in-Time (JIT) compiler at the runtime. Moreover, Julia supports both dynamic as well as static typing. This distinctive feature of Julia differentiates it from the other programming languages.
Type-annotating variables in Julia can be done using the :: operator. This operator confirms that the value on the left is the same type as the value on the right.
expr: It can be an expression for computing a value or an assignment statement for a variable or an declaration of a variable.
type: It is the data type of the variable being used in the program.
Julia type annotations can be used for two types of expressions:
Type Assert: It is an expression that is used for computing a certain value of a variable.
Example 1 :
ERROR: TypeError: in typeassert, expected Int64, got a value of type Float64 Stacktrace:  top-level scope at REPL:1
Variable Type Declaration:
- These are left-hand sides of assignments or declarations of local variables.
- It also covers type fields of a struct and named tuples.
- Function arguments and return type can also be type-annotated.