Optionals (T?
)
Optional or nullable values can be declared either by using the questionmark operator (?
), or by adding an undefined
variant:
- TypeScript
- C++
- Swift
- Kotlin
interface Math extends HybridObject {
a?: number
b: number | undefined
}
class HybridMath: public HybridMathSpec {
std::optional<double> a;
std::optional<double> b;
};
class HybridMath: HybridMathSpec {
var a: Double?
var b: Double?
}
class HybridMath: HybridMathSpec() {
override var a: Double?
override var b: Double?
}
In Kotlin/Java, nullables have to be boxed in object types.