当前位置:网站首页>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
)
边栏推荐
- [HDU 2096] 小明A+B
- ZABBIX customized monitoring disk IO performance
- Two minutes will take you to quickly master the project structure, resources, dependencies and localization of flutter
- Matlab superpixels function (2D super pixel over segmentation of image)
- Recyclerview paging slide
- POJ-2499 Binary Tree
- About cache exceptions: solutions for cache avalanche, breakdown, and penetration
- Matlab imoverlay function (burn binary mask into two-dimensional image)
- End to end neural network
- Correct opening method of redis distributed lock
猜你喜欢
Four operations and derivative operations of MATLAB polynomials
Read and understand the rendering mechanism and principle of flutter's three trees
About cache exceptions: solutions for cache avalanche, breakdown, and penetration
How to clear floating?
MySQL splits strings for conditional queries
Understand redis persistence mechanism in one article
Matlab superpixels function (2D super pixel over segmentation of image)
The evolution of mobile cross platform technology
Course design of compilation principle --- formula calculator (a simple calculator with interface developed based on QT)
Matlab label2idx function (convert the label matrix into a cell array with linear index)
随机推荐
Cypher syntax of neo4j graph database
Summary of C language learning problems (VS)
Take you hand in hand to develop a service monitoring component
Four operations and derivative operations of MATLAB polynomials
[HDU 2096] 小明A+B
GPON other manufacturers' configuration process analysis
Basic operations of MySQL data table, addition, deletion and modification & DML
MySQL function
End to end neural network
Master-slave mode of redis cluster
Learn JVM garbage collection 05 - root node enumeration, security points, and security zones (hotspot)
SENT协议译码的深入探讨
How does MySQL execute an SQL statement?
NPM install reports an error
Swift - enables textview to be highly adaptive
MVVM framework part I lifecycle
Flutter2 heavy release supports web and desktop applications
MySQL stored procedure
MySQL multi table operation
Clear neo4j database data