1

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.

Lii
  • 11,553
  • 8
  • 64
  • 88
Magnus
  • 10,736
  • 5
  • 44
  • 57

2 Answers2

4

We're introducing static members in Ceylon 1.3.1.

There's some more information on this issue.

Gavin King
  • 3,182
  • 1
  • 13
  • 11
3

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

More about it here : Ceylon Docs

Pradeep Pati
  • 5,779
  • 3
  • 29
  • 43