All Downloads are FREE. Search and download functionalities are using the official Maven repository.

samples.expressions.auto-cast.pec Maven / Gradle / Ivy

There is a newer version: 0.0.74
Show newest version
define job as Text attribute

define Person as category with attribute name
define Employee as Person with attribute job

define createPersonOrEmployee as method receiving name and job returning Person doing:
    if job is nothing:
        return Person with name as name
    else:
        return Employee with name as name and job as job

define main as method doing:
    // the below sets the type of p to Person
    p = createPersonOrEmployee with "John" as name and "manager" as job
    // it would be illegal to refer to p.job here
    // because job is not an attribute of Person
    if p is an Employee:
        // now p is treated as an Employee
        printLine "job of Employee p -> " + p.job




© 2015 - 2024 Weber Informatics LLC | Privacy Policy