fun
, PascalCase names: fun Compute(a: Int): Int { ... }
pure fun Hash(o: Object): Int { ... }
IComparable
.class Name implements IFace1, IFace2 { ... }
Fields use val
(immutable) or var
(mutable):
private val Prefix: String
public var Count: Int
Methods must declare access and can be override
/pure
:
public override fun Run(): Int { ... }
static var
is unsafe.Destructor: optional, overrides the implicit virtual destructor from Object
.
public destructor(): Void { ... }
(no parameters, no return).interface IGreeter { fun Greet(name: String): String; }
typealias UserId = Int
fun ProcessUser(id: UserId): Void
::
(e.g., sys::Print
).#import
, #define
, #ifdef
, #ifndef
, #else
, #undef
.Note:
#define
cannot be used to really define something, it is a way to control what code will be used.
call
)call
member that makes instances callable like functions.call
, it may have other members.call
member (maybe not one, with all interface rules applying).fun(...) : T { ... }
can be coerced to a interface type that exposes a compatible call(...) : T
(and only this).Example:
interface CustomFunctional {
call(a: Int?, b: Int?): Int
}
class DefinedFunctional {
public var Multiplier: Int
public fun DefinedFunctional(multiplier: Int): DefinedFunctional {
this.Multiplier = multiplier
return this
}
// Defines the callable behavior; pure body allowed
public call(secondMultiplier: Int): Int = fun(secondMultiplier: Int): Int {
return Multiplier * secondMultiplier
}
}
val AddNullable: CustomFunctional = pure fun(a: Int?, b: Int?): Int {
val aVal: int = a ?: 0 // Conversion from Int? to int
val bVal: int = b ?: 0
return aVal + bVal
}
fun Main(args: StringArray): Int {
// Constructor call then functional call via `call`
return AddNullable(2, DefinedFunctional(-1)(2)) // Implicit conversion from literals
}