渲染zh-Hant

靜態

Translation status: 繁體中文 reader-locale proof. Term names and code fences follow the zh-Hant 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