当前位置:网站首页>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
)边栏推荐
- II. Data type
- struct MySQL
- PXE启动配置及原理
- End to end neural network
- Swift - add navigation bar
- Halcon template matching actual code (I)
- Learning items
- ZABBIX agent2 monitors mongodb templates and configuration operations
- 【ijkplayer】when i compile file “compile-ffmpeg.sh“ ,it show error “No such file or directory“.
- July Huaqing learning-1
猜你喜欢

Ecplise development environment configuration and simple web project construction

Detailed steps for upgrading window mysql5.5 to 5.7.36

Making and using the cutting tool of TTF font library

Learn memory management of JVM 01 - first memory

Redis clean cache

Select drop-down box realizes three-level linkage of provinces and cities in China
Automated test lifecycle

Average lookup length when hash table lookup fails

16 channel water lamp experiment based on Proteus (assembly language)

Keras implements verification code identification
随机推荐
Semantic segmentation experiment: UNET network /msrc2 dataset
[hdu 2096] Xiaoming a+b
The evolution of mobile cross platform technology
Image hyperspectral experiment: srcnn/fsrcnn
Conversion du format de données GPS [facile à comprendre]
Design of music box based on assembly language
Cypher syntax of neo4j graph database
Pytorch two-layer loop to realize the segmentation of large pictures
7月华清学习-1
Learn the memory management of JVM 03 - Method area and meta space of JVM
Ecplise development environment configuration and simple web project construction
UNIX socket advanced learning diary -ipv4-ipv6 interoperability
Complete activity switching according to sliding
Array cyclic shift problem
一款新型的智能家居WiFi选择方案——SimpleWiFi在无线智能家居中的应用
Time tools
Flutter2 heavy release supports web and desktop applications
Just a coincidence? The mysterious technology of apple ios16 is actually the same as that of Chinese enterprises five years ago!
SENT协议译码的深入探讨
ZABBIX agent2 monitors mongodb nodes, clusters and templates (official blog)