当前位置:网站首页>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
)
边栏推荐
- GPON technical standard analysis I
- Migrate data from Mysql to neo4j database
- MySQL installation, Windows version
- Redis master-slave configuration and sentinel mode
- Distributed solution - completely solve website cross domain requests
- Solve the problem of cache and database double write data consistency
- Hexadecimal conversion summary
- Implementing Yang Hui triangle with cyclic queue C language
- How to design an interface?
- Conversion du format de données GPS [facile à comprendre]
猜你喜欢
[figure neural network] GNN from entry to mastery
Yum only downloads the RPM package of the software to the specified directory without installing it
Resnet+attention project complete code learning
在家庭智能照明中应用的测距传感芯片4530A
Pytoch monolayer bidirectional_ LSTM implements MNIST and fashionmnist data classification
Get data from the database when using JMeter for database assertion
About LDA model
上午面了个腾讯拿 38K 出来的,让我见识到了基础的天花
Take you two minutes to quickly master the route and navigation of flutter
JDBC -- use JDBC connection to operate MySQL database
随机推荐
Anaconda creates a virtual environment and installs pytorch
NLP engineer learning summary and index
How can beginners learn flutter efficiently?
About LDA model
Learning JVM garbage collection 06 - memory set and card table (hotspot)
UNIX socket advanced learning diary -ipv4-ipv6 interoperability
A new WiFi option for smart home -- the application of simplewifi in wireless smart home
Redis highly available sentinel cluster
[superhard core] is the core technology of redis
Time conversion error
Learn the memory management of JVM 02 - memory allocation of JVM
Average lookup length when hash table lookup fails
VoneDAO破解组织发展效能难题
Distributed solution - distributed lock solution - redis based distributed lock implementation
Making and using the cutting tool of TTF font library
Solve the error 1045 of Navicat creating local connection -access denied for user [email protected] (using password
C alarm design
ZABBIX 5.0 - LNMP environment compilation and installation
上午面了个腾讯拿 38K 出来的,让我见识到了基础的天花
Volatile instruction rearrangement and why instruction rearrangement is prohibited