Interfaces, Enums, and Annotations
Beyond regular classes, Klyn provides interfaces for contracts, enums for symbolic states, and annotations for metadata. These three forms are small but important pieces of the language.
interface DoSomething:
public doSomething() as Int
public abstract doSomethingElse() as Int
public static version() as Int:
return 1
Interface methods are abstract by default. Static interface members are also allowed when they make the contract easier to consume.
enum Color:
RED
GREEN
BLUE
enum ColorName:
RED = "red"
GREEN = "green"
BLUE = "blue"
public readonly property value as String
public ColorName(value as String):
this.value = value
Simple enums receive integer values by default. You can also define explicit payload values and properties when the enum needs richer data.
annotation Deprecated:
pass
@Deprecated
class LegacyApi:
pass
Annotations attach metadata to declarations. They are commonly used for testing, tooling, and API lifecycle markers.
annotation TestClass:
public readonly property category as String = null
public TestClass(category as String):
this.category = category
@TestClass(category="Unit")
class MathTests:
pass
Annotation arguments use the same named-argument style you see in ordinary calls.
@klyn.unittest.TestClass
class DemoTests:
pass
Qualified annotation names are useful when you want to avoid ambiguity or do not want an extra import for a short file.