實作
Translation status: 繁體中文 reader-locale proof. Term names and code fences follow the zh-Hant pack; supporting prose may still be English.
Declares that a type implements one or more 待實作介面 contracts.
Aliases: implements
Syntax: 類型 <name> 實作 <interface-list> <block>
Category#
type
Related#
Examples#
radix/corpus/implet/implet.fab (canonical · keyword)#
Declares that a type implements one or more 待實作介面 contracts.
# =============================================================================
# 實作 — Declares that a type implements one or more 待實作介面 contracts
# =============================================================================
#
# What this teaches:
# • Declares that a type implements one or more 待實作介面 contracts.
# • Related keywords: 類型, 待實作介面
#
# Common mistakes:
# • Declaring `類型 實作 Implendum` without implementing all required methods — every method signature in the 待實作介面 must have a body in the 類型.
#
# See also: 類型, 待實作介面
# =============================================================================
# 實作 — 類型 implements a 待實作介面 (interface contract)
#
# 類型 Nomen 實作 Implendum { … }
#
# GRAMMAR:
# genusDecl :← '類型' ident '實作' ident '{' methodDecl* '}'
#
# EXPECTED OUTPUT:
# implet.expected — Aurelia from 待實作介面 plenum().
interface Nominatum {
fn plenum() → string
}
class Civis implements Nominatum {
var string 名稱
fn plenum() → string {
# satisfies 待實作介面 requirement
return "§"(self.nomen)
}
}
main {
const Civis civis ← Civis { 名稱 = "Aurelia" }
print civis.plenum()
}Expected output:
Aurelia