当前位置:网站首页>Kotlin函数
Kotlin函数
2022-07-05 12:32:00 【好奇的菜鸟】
一、函数定义
/*
关键字 函数名 参数类型 返回值类型
↓ ↓ ↓ ↓ */
fun helloFunction(name: String): String {
return "Hello $name !"
}/* ↑
花括号内为:函数体
*/
简写
fun helloFunction(name: String): String = "Hello $name !"
fun helloFunction(name: String) = "Hello $name !"
二、函数调用
helloFunction("Kotlin")
helloFunction(name = "Kotlin")
三、函数默认参数
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
) {
//..
}
有默认值得参数可以不传
createUser(
name = "Tom",
age = 30,
commentCount = 3285
)
边栏推荐
- 手机 CPU 架构类型了解
- 语义分割实验:Unet网络/MSRC2数据集
- Third party payment interface design
- Resnet18 actual battle Baoke dream spirit
- Cypher syntax of neo4j graph database
- Take you two minutes to quickly master the route and navigation of flutter
- Leetcode-1. Sum of two numbers (Application of hash table)
- PXE启动配置及原理
- Reinforcement learning - learning notes 3 | strategic learning
- Flutter2 heavy release supports web and desktop applications
猜你喜欢
Seven ways to achieve vertical centering
嵌入式软件架构设计-消息交互
ZABBIX ODBC database monitoring
Resnet+attention project complete code learning
Matlab struct function (structure array)
MySQL splits strings for conditional queries
About cache exceptions: solutions for cache avalanche, breakdown, and penetration
Pytorch two-layer loop to realize the segmentation of large pictures
强化学习-学习笔记3 | 策略学习
The relationship between the size change of characteristic graph and various parameters before and after DL convolution operation
随机推荐
[HDU 2096] 小明A+B
The evolution of mobile cross platform technology
MySQL data table operation DDL & data type
A guide to threaded and asynchronous UI development in the "quick start fluent Development Series tutorials"
Distributed solution - completely solve website cross domain requests
什么是数字化存在?数字化转型要先从数字化存在开始
Time tools
II. Data type
【ijkplayer】when i compile file “compile-ffmpeg.sh“ ,it show error “No such file or directory“.
Swift - add navigation bar
PXE startup configuration and principle
Acid transaction theory
Pytoch through datasets Imagefolder loads datasets directly from files
Clear neo4j database data
How can beginners learn flutter efficiently?
GPON other manufacturers' configuration process analysis
Anaconda creates a virtual environment and installs pytorch
Xi IO flow
Matlab label2idx function (convert the label matrix into a cell array with linear index)
Understanding the architecture type of mobile CPU