当前位置:网站首页>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
)
边栏推荐
- Master-slave mode of redis cluster
- Redis's memory elimination mechanism, read this article is enough.
- Pytoch monolayer bidirectional_ LSTM implements MNIST and fashionmnist data classification
- SENT协议译码的深入探讨
- About cache exceptions: solutions for cache avalanche, breakdown, and penetration
- MySQL basic operation -dql
- Seven ways to achieve vertical centering
- Matlab superpixels function (2D super pixel over segmentation of image)
- 只是巧合?苹果 iOS16 的神秘技术竟然与中国企业 5 年前产品一致!
- MySQL data table operation DDL & data type
猜你喜欢
Get all stock data of big a
Pytoch implements tf Functions of the gather() function
强化学习-学习笔记3 | 策略学习
Redis highly available sentinel cluster
Get data from the database when using JMeter for database assertion
Ecplise development environment configuration and simple web project construction
UNIX socket advanced learning diary -ipv4-ipv6 interoperability
Four operations and derivative operations of MATLAB polynomials
Third party payment interface design
Resnet+attention project complete code learning
随机推荐
MySQL regular expression
Seven ways to achieve vertical centering
Learn the memory management of JVM 02 - memory allocation of JVM
Course design of compilation principle --- formula calculator (a simple calculator with interface developed based on QT)
How to design an interface?
PXE启动配置及原理
byte2String、string2Byte
Take you two minutes to quickly master the route and navigation of flutter
Flutter2 heavy release supports web and desktop applications
Keras implements verification code identification
Programming skills for optimizing program performance
Matlab superpixels function (2D super pixel over segmentation of image)
【ijkplayer】when i compile file “compile-ffmpeg.sh“ ,it show error “No such file or directory“.
Average lookup length when hash table lookup fails
ZABBIX customized monitoring disk IO performance
手机 CPU 架构类型了解
mysql拆分字符串做条件查询
MySQL storage engine
[figure neural network] GNN from entry to mastery
Master the new features of fluent 2.10