thp-lang.org/md/learn/classes/anonymous.md
2023-11-04 07:17:32 -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
    }
})