Search code examples
javastaticceylon

Equivalent to the Java "static" keyword in Ceylon


I wondered if the Ceylon programming language features an equivalent to the "static" keyword in Java, or if there's some common idiom that's used in its place.

Edit: elaborating on the answer, here's an example of a scoped "function" (its syntax is identical to a method) that can be invoked without a class instance, in other words it's just like a static Java method. Notice the key difference is that this is defined inside an "object" instead of a "class", which effectively makes a singleton with no need to instantiate:

object mystaticstuff {
    shared void introduceYourself() {
        print "madam, im adam";
    }
}

Note you could also declare the method/function outside of any class or object, in which case it just floats freely in your "global" (still scoped to your package) namespace.


Solution

  • There are no static members in Ceylon. Rather there are toplevel functions, declared in the package.

    More about it here : Ceylon Docs