当前位置:网站首页>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
)
边栏推荐
- A new WiFi option for smart home -- the application of simplewifi in wireless smart home
- How to recover the information server and how to recover the server data [easy to understand]
- Pytoch implements tf Functions of the gather() function
- MySQL index - extended data
- Pytoch uses torchnet Classerrormeter in meter
- Read and understand the rendering mechanism and principle of flutter's three trees
- NPM install reports an error
- Full text search of MySQL
- 10 minute fitness method reading notes (1/5)
- Migrate data from Mysql to neo4j database
猜你喜欢
OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首
Constructing expression binary tree with prefix expression
MySQL index (1)
JDBC -- use JDBC connection to operate MySQL database
Pytoch implements tf Functions of the gather() function
Take you hand in hand to develop a service monitoring component
Volatile instruction rearrangement and why instruction rearrangement is prohibited
Principle of universal gbase high availability synchronization tool in Nanjing University
Implementing Yang Hui triangle with cyclic queue C language
从39个kaggle竞赛中总结出来的图像分割的Tips和Tricks
随机推荐
Get data from the database when using JMeter for database assertion
JDBC -- extract JDBC tool classes
How can beginners learn flutter efficiently?
10 minute fitness method reading notes (2/5)
Resnet+attention project complete code learning
一款新型的智能家居WiFi选择方案——SimpleWiFi在无线智能家居中的应用
POJ-2499 Binary Tree
MySQL trigger
OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首
Rasa Chat Robot Tutorial (translation) (1)
SENT协议译码的深入探讨
Principle of universal gbase high availability synchronization tool in Nanjing University
Time conversion error
SAP 自开发记录用户登录日志等信息
struct MySQL
Kotlin流程控制、循环
Keras implements verification code identification
Experimental design - using stack to realize calculator
Two minutes will take you to quickly master the project structure, resources, dependencies and localization of flutter
[figure neural network] GNN from entry to mastery