thp-lang.org/md/learn/classes/static.md
2023-10-23 20:39:34 -05:00

516 B

Static in classes

Class constants

class Cat
{
    // Stateful code
}

static Cat
{
    const CONSTANT = "constant value"
}

print(Cat::CONSTANT)

Static methods

aka. plain, old functions

static Cat
{
    fun static_method() -> Int
    {
        // ...
    }
}

Cat::static_method()

Static properties

aka. global variables

static Cat
{
    pub var access_count = 0
}

print(Cat::access_count)    // 0
Cat::access_count += 1
print(Cat::access_count)    // 1