Pergunta

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.

Foi útil?

Solução 2

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

More about it here : Ceylon Docs

Outras dicas

We're introducing static members in Ceylon 1.3.1.

There's some more information on this issue.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top