c# | swift | kotlin | java |
---|---|---|---|
byte | - | Byte | byte |
bool | Bool | Boolean | boolean |
int | Int | Int | int |
long | - | Long | long |
float | Float | Float | float |
double | Double | Double | double |
string | String | String | String |
decimal | Decimal | BigDecimal | BigDecimal |
c# | swift | kotlin | java |
---|---|---|---|
int? | Int? | Int? | Integer |
string | String? | String? | String |
decimal? | Decimal? | BigDecimal? | BigDecimal |
c# | swift | kotlin | java |
---|---|---|---|
var a = 1 | let a: Int = 1 | val a: Int = 1 | final int a = 1 |
var a = 1 | var a: Int = 1 | var a: Int = 1 | int a = 1 |
c# | swift | kotlin | java |
---|---|---|---|
async (p1, p2) => { ... } | { (p1: type1, p2: type2) in ... } | { p1, p2 -> .... } | (p1, p2) -> { ... } |
c# | swift | kotlin | java |
---|---|---|---|
class Name: Base | class Name: Base | class Name: Base | class Name extends Base |
class Name: Interface | class Name: Protocol | class Name: Interface | class Name implements Interface |
kotlin默认类不能被继承,如果需要被继承,需要使用关键字
open
c# | swift | kotlin | java |
---|---|---|---|
ClassName(int p) | init(p: Int) | constructor(p: Int) | ClassName(int p) |
kotlin可以有一个一级构造方法和多个二级构造方法,一级构造方法定义在类名后面。另外,kotlin还有初始方法
init
,执行顺序依次为一级构造方法、初始方法、二级构造方法。
c# | swift | kotlin | java |
---|---|---|---|
int Name(int p) | func name(p: Int) -> Int | fun name(p: Int): Int | int name(int p) |
void Name(int p) | func name(p: Int) -> Void | fun name(p: Int): Unit | void name(int p) |
Swift和kotlin的
Void
和Unit
可以省略