当前位置:网站首页>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
)边栏推荐
- Preliminary exploration of basic knowledge of MySQL
- MySQL multi table operation
- Solve the problem of cache and database double write data consistency
- Learning items
- Differences between IPv6 and IPv4 three departments including the office of network information technology promote IPv6 scale deployment
- Introduction to GNN
- Learn garbage collection 01 of JVM -- garbage collection for the first time and life and death judgment
- 一款新型的智能家居WiFi选择方案——SimpleWiFi在无线智能家居中的应用
- The relationship between the size change of characteristic graph and various parameters before and after DL convolution operation
- Cypher syntax of neo4j graph database
猜你喜欢

Redis's memory elimination mechanism, read this article is enough.

Redis highly available sentinel mechanism

Master-slave mode of redis cluster

Iterator details in list... Interview pits

Constructing expression binary tree with prefix expression

Why learn harmonyos and how to get started quickly?

Master the new features of fluent 2.10

Keras implements verification code identification

Annotation problem and hidden Markov model

C language structure is initialized as a function parameter
随机推荐
Average lookup length when hash table lookup fails
Distributed solution - distributed session consistency problem
MySQL trigger
struct MySQL
Why learn harmonyos and how to get started quickly?
Preliminary exploration of basic knowledge of MySQL
Redis cluster configuration
Distributed solution - completely solve website cross domain requests
ZABBIX 5.0 - LNMP environment compilation and installation
ZABBIX agent2 monitors mongodb nodes, clusters and templates (official blog)
Just a coincidence? The mysterious technology of apple ios16 is actually the same as that of Chinese enterprises five years ago!
ActiveMQ installation and deployment simple configuration (personal test)
Keras implements verification code identification
Handwriting blocking queue: condition + lock
POJ-2499 Binary Tree
NLP engineer learning summary and index
Programming skills for optimizing program performance
Understand kotlin from the perspective of an architect
NPM install reports an error
Get all stock data of big a