当前位置:网站首页>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
)边栏推荐
- Matlab imoverlay function (burn binary mask into two-dimensional image)
- Automated test lifecycle
- 语义分割实验:Unet网络/MSRC2数据集
- Interviewer: is acid fully guaranteed for redis transactions?
- Distributed solution - distributed session consistency problem
- Array cyclic shift problem
- How to design an interface?
- ZABBIX customized monitoring disk IO performance
- Read and understand the rendering mechanism and principle of flutter's three trees
- The evolution of mobile cross platform technology
猜你喜欢

Pytoch uses torchnet Classerrormeter in meter

MySQL storage engine

Making and using the cutting tool of TTF font library

强化学习-学习笔记3 | 策略学习

Redis highly available sentinel cluster

Resnet18 actual battle Baoke dream spirit

Why learn harmonyos and how to get started quickly?

Interviewer: is acid fully guaranteed for redis transactions?

Implementing Yang Hui triangle with cyclic queue C language
Two minutes will take you to quickly master the project structure, resources, dependencies and localization of flutter
随机推荐
Distributed solution - Comprehensive decryption of distributed task scheduling platform -xxljob
Conversion du format de données GPS [facile à comprendre]
Migrate data from Mysql to neo4j database
Pytoch implements tf Functions of the gather() function
A new WiFi option for smart home -- the application of simplewifi in wireless smart home
嵌入式软件架构设计-消息交互
The evolution of mobile cross platform technology
Detailed steps for upgrading window mysql5.5 to 5.7.36
Distributed solution - completely solve website cross domain requests
Storage Basics
ZABBIX monitors mongodb (template and deployment operations)
Anaconda creates a virtual environment and installs pytorch
Resnet18 actual battle Baoke dream spirit
MySQL index - extended data
MySQL installation, Windows version
Programming skills for optimizing program performance
Solution to order timeout unpaid
GPS數據格式轉換[通俗易懂]
A guide to threaded and asynchronous UI development in the "quick start fluent Development Series tutorials"
Understanding the architecture type of mobile CPU