渲染zh-Hans

静态

Translation status: 简体中文 reader-locale proof. Term names and code fences follow the zh-Hans pack; supporting prose may still be English.

Marks a class member as belonging to the type itself.

Syntax: 静态 <type> <name> [= <expression>]

Category#

type

Examples#

radix/corpus/generis/generis.fab (canonical · keyword)#

Marks a class member as belonging to the type itself.

# =============================================================================
# 静态 — 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: 类, ego
#
# Common mistakes:
#   • Accessing a `静态` field on an instance instead of the type — `静态` fields are static members accessed via the 类 name, not via `ego`.
#
# See also: 类, ego
# =============================================================================

# 静态 marks a static 类 field (shared across instances)
#
# 静态 <type> <field> = <initium>  -- class-level binding, not per-instance
#
# GRAMMAR:
#   fieldDecl inside genusDecl :← '静态'? type ident ('=' expr)?
#
# EXPECTED OUTPUT:
#   ruber
#
# Instance field `名称` is per-object; `静态 ruber` would be accessed on the
# 类 type in full programs (here only instance fields are read).

class Color {
    static string ruber = "#ff0000"
    var string 名称 = "ruber"
}

main {
    const Color color ← Color {}
    print color.nomen
}

Expected output:

ruber