Files
hakorune/docs/guides/examples/visibility_error.hako

28 lines
686 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

static box Main {
init { console }
main() {
me.console = new ConsoleBox()
box User {
private { age, passwordHash }
public { name }
init { name, age }
birth(n, a) {
me.name = n
me.age = a
}
}
local u = new User("Alice", 20)
me.console.log("name(public)=" + u.name) # OK: public
# 以下は外部からprivateフィールドへのアクセス → エラーになる想定
u.age = 30 # 外部からの代入NG
me.console.log(u.age) # 外部からの参照NG
}
}