Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Self within type to call static methods #497

Open
kengorab opened this issue Nov 14, 2024 · 0 comments
Open

Using Self within type to call static methods #497

kengorab opened this issue Nov 14, 2024 · 0 comments

Comments

@kengorab
Copy link
Owner

kengorab commented Nov 14, 2024

Given a type MyType or enum MyEnum, static methods on that type/enum should be callable using the Self type, rather than requiring the whole type be spelled. For example:

type MyType {
  func staticFunc(): Int = 123
  func method() {
    // val num = MyType.staticFunc()
    val num = Self.staticFunc() // <- do this instead
    println(num)
  }
}

This has a couple of implications.

  1. Self is effectively keyworded, like self
  2. Selfis not a valid type identifier anymore
  3. Self cannot be used outside of a method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant