当前位置:网站首页>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
)边栏推荐
- Pytoch monolayer bidirectional_ LSTM implements MNIST and fashionmnist data classification
- MySQL multi table operation
- Recyclerview paging slide
- [hdu 2096] Xiaoming a+b
- PXE启动配置及原理
- 语义分割实验:Unet网络/MSRC2数据集
- Redis clean cache
- Get the variable address of structure member in C language
- Conversion du format de données GPS [facile à comprendre]
- 手机 CPU 架构类型了解
猜你喜欢

C language structure is initialized as a function parameter
A guide to threaded and asynchronous UI development in the "quick start fluent Development Series tutorials"

Resnet18 actual battle Baoke dream spirit

Matlab superpixels function (2D super pixel over segmentation of image)

Get all stock data of big a

MySQL transaction

Pytoch uses torchnet Classerrormeter in meter

Migrate data from Mysql to neo4j database

Learn memory management of JVM 01 - first memory

One article tells the latest and complete learning materials of flutter
随机推荐
Array cyclic shift problem
Redis highly available sentinel cluster
Master the new features of fluent 2.10
Constructing expression binary tree with prefix expression
Matlab boundarymask function (find the boundary of the divided area)
Just a coincidence? The mysterious technology of apple ios16 is actually the same as that of Chinese enterprises five years ago!
Understanding the architecture type of mobile CPU
Distributed solution - Comprehensive decryption of distributed task scheduling platform -xxljob
Summary of C language learning problems (VS)
MySQL stored procedure
7月华清学习-1
How to clear floating?
Correct opening method of redis distributed lock
Take you two minutes to quickly master the route and navigation of flutter
Read and understand the rendering mechanism and principle of flutter's three trees
Get the variable address of structure member in C language
Solve the problem of cache and database double write data consistency
MySQL installation, Windows version
byte2String、string2Byte
C alarm design