thp-lang.org/md/learn/classes/anonymous.md
2023-11-04 07:17:32 -05:00

35 lines
395 B
Markdown

# Anonymous classes
```thp
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)
}
})
```
```thp
setLogger(class(Int param1) -> SomeClass(param1), SomeInterface
{
pub fun method()
{
// code
}
})
```