当前位置:网站首页>Basic use of kotlin
Basic use of kotlin
2022-07-04 19:42:00 【AdleyTales】
fun main() {
println("hello world, Hello Kotlin ~")
val result = sum(12, 5)
println(result) // 17
val result2 = sum2(12, 5)
println(result2) // 17
val result3 = sum2(12, 5)
println(result3) // 17
varsFunc("aaaa", "bbbb", "cccc", "dddd", " Ying pengliang ")
println("******------******------******------******------******------******------")
// Define constants and variables val Same as java Of final
val firstname = "adley"
val lastname = "tales"
// String template
val str = "My name is $firstname $lastname !"
println(str)
// NULL Inspection mechanism
// Air safety Add... After the field !! image Java Throw an empty exception , Another field is followed by ? Do not process the return value is null perhaps ?: Short judgment processing
// Type followed by ? Can be empty
var name: String? = "adley"
name = null
println(name)
// Throws a null pointer exception
// var age = name!!.toInt()
// Return... Without processing null
val age2 =name?.toInt()
println(age2) // null
val ages3 = age2?.toInt() ?: -1 // If it's empty , Then for -1
println(ages3) // -1
println(name is String) // false
println(str is String) // true
// Section
for (i in 1..5) {
println(i)
}
for (i in 1..5 step 2) {
println(i)
}
}
// Basic usage
// Package declaration : package com.adleytales.demo
// Function definition
fun sum(x: Int, y: Int): Int {
return x + y
}
// function
fun sum2(x: Int, y: Int): Int = x + y
// function lambda
val sum3: (Int, Int) -> Int = {
x, y -> x + y }
// Variable length parameters vararg
fun varsFunc(vararg str: String) {
for (s in str) {
println(s)
}
}
边栏推荐
- Niuke Xiaobai month race 7 e applese's super ability
- BCG 使用之CBCGPProgressDlg进度条使用
- 黑马程序员-软件测试--08阶段2-linux和数据库-23-30-进程端口相关,修改文件权限,端口号信息的获取,程序和进程相关操作,linux命令案例
- node_ Exporter deployment
- Oracle with as ora-00903: invalid table name multi report error
- Multi table operation inner join query
- Specify the character set to output
- BCG 使用之新建向导效果
- . Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
- 指定输出的字符集
猜你喜欢
C # use stopwatch to measure the running time of the program
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
C语言-入门-基础-语法-流程控制(七)
PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
BCG 使用之CBCGPProgressDlg进度条使用
Stream stream
Siemens HMI download prompts lack of panel image solution
BCG 使用之CBCGPTabWnd控件(相当于MFC TabControl)
Oracle with as ORA-00903: invalid table name 多表报错
Detailed explanation of the binary processing function threshold() of opencv
随机推荐
添加命名空间声明
Oracle with as ora-00903: invalid table name multi report error
Socket programming demo II
1002. A+B for Polynomials (25)(PAT甲级)
HDU 6440 2018 Chinese college student program design network competition
页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
Detailed explanation of the binary processing function threshold() of opencv
JVM系列之对象的创建
The difference and usage between substr (), slice (), and substring () in the string interception methods of "understand series after reading"
1006 sign in and sign out (25 points) (PAT class a)
牛客小白月赛7 谁是神箭手
mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
指定输出的字符集
Specify the character set to output
Mysql database basic operation -ddl | dark horse programmer
Cbcgpprogressdlgctrl progress bar used by BCG
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
Master the use of auto analyze in data warehouse
欧拉函数
YOLOv5s-ShuffleNetV2