ComeçarComece de graça

Mutable and typed structs

We've created our type Employee and have created an instance employee to store the details of our CEO. But some of the details will change over time - our CEO might change his name, his age will increase, and he might change his location. We want to keep up-to-date records of our employees, and so we need to be able to update the fields within our employee instance.

We also want to constrain the type of data that is filled out. When our data entry team enters the details of an employee, we want to safeguard against any accidental errors. We want to force:

  • the name to be a string
  • the age to be an integer value
  • the location to be a string

Recall that to create a mutable struct, we use the mutable keyword.

Este exercício faz parte do curso

Intermediate Julia

Ver curso

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Create a mutable struct Employee
____ struct Employee
    name
    location
    age
end
Editar e executar o código