thp-lang.org/md/learn/classes/anonymous.md
2023-10-05 07:56:34 -05:00

395 B

Anonymous classes

class Logger
{
    pub fun log(String msg)
    {
        print(msg)
    }
}

// Using a class instance
setLogger(Logger())

// Using an anonymous class
setLogger(class {
    pub fun log(String msg)
    {
        print(msg)
    }
})
setLogger(class(Int param1) -> SomeClass(param1), SomeInterface {
    pub fun method()
    {
        // code
    }
})