《Kotlin极简教程》第二章 Hello,World 函数
来源:互联网 发布:定格动画软件 编辑:程序博客网 时间:2024/06/13 17:24
最新上架!!!
《 Kotlin极简教程》 陈光剑 (机械工业出版社):
https://mp.weixin.qq.com/s/bzRkGSO6T1O2AELM_UqKUQ
此开篇第二回。
直接来说: Hello,World!
HelloWorld.kt
/** * We declare a package-level function main which returns Unit and takes * an Array of strings as a parameter. Note that semicolons are optional. */fun main(args: Array<String>) { println("Hello, world!")}
函数
函数声明
在Kotlin中,函数声明使用关键字 fun
fun double(x: Int): Int {}
函数调用
调用函数使用传统的方法
val result = double(2)
更多示例
带有两个 Int 参数、返回 Int的函数:
fun sum(a: Int, b: Int): Int { return a + b}
将表达式作为函数体、返回值类型自动推断的函数:
fun sum(a: Int, b: Int) = a + b
函数返回无意义的值:
fun printSum(a: Int, b: Int): Unit { print(a + b)}
Unit返回类型可以省略:
fun printSum(a: Int, b: Int) { print(a + b)}
阅读全文
1 0
- 《Kotlin极简教程》第二章 Hello,World 函数
- 《Springboot极简教程》 Springboot plus Kotlin :Hello,World
- (转载)如何让孩子爱上Kotlin第二章:Hello World
- Hello World With Kotlin
- Kotlin的hello world
- kotlin hello world
- Hello World Kotlin
- 《Kotlin极简教程》第二章 快速开始:HelloWorld 配图
- 《React极简教程》第一章 Hello,World!
- 第二章 出发"Hello World"
- 【C++】第二章:Hello World!
- Kotlin 学习(1) -- Hello World
- 用kotlin说Hello World
- Kotlin 之hello world篇
- AutoCAD.NET:第二章 Hello World
- 第二章 :Hello World 应用程序详解
- 第二章Hello World-跟赵大笨笨学SpringMVC
- 《Kotlin极简教程》第六章 Kotlin函数式编程(FP)
- 基于R的数据挖掘方法与实践(1)——数据准备
- 《Springboot极简教程》 Springboot plus Kotlin :Hello,World
- 《Springboot极简教程》使用Spring Boot, JPA, Mysql, ThymeLeaf,gradle, Kotlin快速构建一个CRUD Web App
- 《Kotlin极简教程》第一章 Kotlin简介
- linux shell脚本执行错误:bad substitution
- 《Kotlin极简教程》第二章 Hello,World 函数
- 《Kotlin极简教程》第三章 Kotlin基本数据类型
- 《Kotlin极简教程》第六章 Kotlin函数式编程(FP)
- 《Kotlin极简教程》第五章 Kotlin面向对象编程(OOP)
- 《Kotlin极简教程》第四章 Kotlin基础语法
- 《Kotlin极简教程》第七章 Kotlin 集成 Springboot开发WebApp
- Linux之ps命令
- 测试思考拾叶集
- 测试金字塔 TestPyramid