kotlin入门(研究一下官方文档)

创建项目

Intellij IDEAnew ->project选择Interllij的system,选择add sample code,开始就生成一个hello word的程序

1
2
3
4
fun main()
{
println("hellow world!")
}

fun用来创建一个函数,经典的main()函数为程序的开始地方,这创建函数

read-only variables(常量)用val

Mutable variables用var

string templates(字符串模板)->在字符串中invert(嵌入值)用sign $,而模板中对一段代码求值还是用$ + curly braces{}

1
2
3
4
5
6
fun main()
{
val theme = 10
println("There are $theme customers")
println("There are ${theme + 1} customers")
}

basic types

很关键,根据数据类型可知道其含有那些functions与properties(属性)

category(类型) basic types Example code
Intergers(整数) Byte,short,Int,Long val amount: Long = 250_0000_000
Unsigned Intergers UBYte,Ushort

基础语法

包声明

1
package com.runob