当前位置:网站首页>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 storage engine
- Redis highly available slice cluster
- Solve the error 1045 of Navicat creating local connection -access denied for user [email protected] (using password
- [figure neural network] GNN from entry to mastery
- Distributed solution - distributed lock solution - redis based distributed lock implementation
- Understand redis persistence mechanism in one article
- 在家庭智能照明中应用的测距传感芯片4530A
- GNN(pytorch-geometric)
- MySQL stored procedure
- Handwriting blocking queue: condition + lock
猜你喜欢
激动人心!2022开放原子全球开源峰会报名火热开启!
Making and using the cutting tool of TTF font library
ActiveMQ installation and deployment simple configuration (personal test)
One article tells the latest and complete learning materials of flutter
Anaconda creates a virtual environment and installs pytorch
UNIX socket advanced learning diary - advanced i/o functions
Resnet18 actual battle Baoke dream spirit
UNIX socket advanced learning diary -ipv4-ipv6 interoperability
Understand kotlin from the perspective of an architect
Yum only downloads the RPM package of the software to the specified directory without installing it
随机推荐
Deep discussion on the decoding of sent protocol
Redis clean cache
Kotlin函数
Volatile instruction rearrangement and why instruction rearrangement is prohibited
Instance + source code = see through 128 traps
POJ-2499 Binary Tree
Get the variable address of structure member in C language
Yum only downloads the RPM package of the software to the specified directory without installing it
Conversion du format de données GPS [facile à comprendre]
SENT协议译码的深入探讨
UNIX socket advanced learning diary -ipv4-ipv6 interoperability
ZABBIX agent2 monitors mongodb templates and configuration operations
Redis master-slave configuration and sentinel mode
MySQL stored procedure
Redis's memory elimination mechanism, read this article is enough.
MySQL multi table operation
Just a coincidence? The mysterious technology of apple ios16 is actually the same as that of Chinese enterprises five years ago!
GPS數據格式轉換[通俗易懂]
Semantic segmentation experiment: UNET network /msrc2 dataset
Knowledge representation (KR)