当前位置:网站首页>Kotlin function
Kotlin function
2022-07-05 12:42:00 【Curious rookie】
One 、 Function definition
/*
keyword Function name Parameter type return type
↓ ↓ ↓ ↓ */
fun helloFunction(name: String): String {
return "Hello $name !"
}/* ↑
Inside the curly brackets is : The body of the function
*/
Abbreviation
fun helloFunction(name: String): String = "Hello $name !"
fun helloFunction(name: String) = "Hello $name !"
Two 、 Function call
helloFunction("Kotlin")
helloFunction(name = "Kotlin")
3、 ... and 、 Function default parameters
fun createUser(
name: String,
age: Int,
gender: Int = 1,
friendCount: Int = 0,
feedCount: Int = 0,
likeCount: Long = 0L,
commentCount: Int = 0
) {
//..
}
fun createUser(
name: String,
age: Int,
gender: Int = 1,
friendCount: Int = 0,
feedCount: Int = 0,
likeCount: Long = 0L,
commentCount: Int = 0
) {
//..
}
Parameters with default values can be omitted
createUser(
name = "Tom",
age = 30,
commentCount = 3285
)
边栏推荐
- MySQL multi table operation
- Distributed solution - completely solve website cross domain requests
- 前几年外包干了四年,秋招感觉人生就这样了..
- ZABBIX customized monitoring disk IO performance
- Learning JVM garbage collection 06 - memory set and card table (hotspot)
- 一款新型的智能家居WiFi选择方案——SimpleWiFi在无线智能家居中的应用
- Get data from the database when using JMeter for database assertion
- Get all stock data of big a
- II. Data type
- ZABBIX agent2 installation
猜你喜欢
Average lookup length when hash table lookup fails
ZABBIX customized monitoring disk IO performance
The relationship between the size change of characteristic graph and various parameters before and after DL convolution operation
Resnet+attention project complete code learning
Take you two minutes to quickly master the route and navigation of flutter
OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首
VoneDAO破解组织发展效能难题
Constructing expression binary tree with prefix expression
Principle of universal gbase high availability synchronization tool in Nanjing University
UNIX socket advanced learning diary - advanced i/o functions
随机推荐
Time conversion error
Learning JVM garbage collection 06 - memory set and card table (hotspot)
Pytorch two-layer loop to realize the segmentation of large pictures
ZABBIX agent2 monitors mongodb templates and configuration operations
Iterator details in list... Interview pits
从39个kaggle竞赛中总结出来的图像分割的Tips和Tricks
OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首
激动人心!2022开放原子全球开源峰会报名火热开启!
JDBC -- use JDBC connection to operate MySQL database
Sqoop import and export operation
GNN(pytorch-geometric)
Image hyperspectral experiment: srcnn/fsrcnn
Anaconda creates a virtual environment and installs pytorch
GPS數據格式轉換[通俗易懂]
MySQL function
Kotlin流程控制、循环
Understand kotlin from the perspective of an architect
VoneDAO破解组织发展效能难题
IPv6与IPv4的区别 网信办等三部推进IPv6规模部署
GPS数据格式转换[通俗易懂]