tĩnh
Translation status: Tiếng Việt reader-locale proof. Term names and code fences follow the vi pack; supporting prose may still be English.
Marks a class member as belonging to the type itself.
Syntax: tĩnh <type> <name> [= <expression>]
Category#
type
Related#
Examples#
radix/corpus/generis/generis.fab (canonical · keyword)#
Marks a class member as belonging to the type itself.
# =============================================================================
# tĩnh — Marks a class member as belonging to the type itself
# =============================================================================
#
# What this teaches:
# • Marks a class member as belonging to the type itself.
# • Related keywords: kiểu, ego
#
# Common mistakes:
# • Accessing a `tĩnh` field on an instance instead of the type — `tĩnh` fields are static members accessed via the kiểu name, not via `ego`.
#
# See also: kiểu, ego
# =============================================================================
# tĩnh marks a static kiểu field (shared across instances)
#
# tĩnh <type> <field> = <initium> -- class-level binding, not per-instance
#
# GRAMMAR:
# fieldDecl inside genusDecl :← 'tĩnh'? type ident ('=' expr)?
#
# EXPECTED OUTPUT:
# ruber
#
# Instance field `tên` is per-object; `tĩnh ruber` would be accessed on the
# kiểu type in full programs (here only instance fields are read).
class Color {
static string ruber = "#ff0000"
var string tên = "ruber"
}
main {
const Color color ← Color {}
print color.nomen
}Expected output:
ruber