当前位置:网站首页>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)
}
}
边栏推荐
猜你喜欢
Multi table operation - external connection query
"Only one trip", active recommendation and exploration of community installation and maintenance tasks
Chrome开发工具:VMxxx文件是什么鬼
Hough Transform 霍夫变换原理
黑马程序员-软件测试--08阶段2-linux和数据库-23-30-进程端口相关,修改文件权限,端口号信息的获取,程序和进程相关操作,linux命令案例
Hough transform Hough transform principle
多表操作-内连接查询
Some thoughts on whether the judgment point is located in the contour
C# 使用StopWatch测量程序运行时间
BCG 使用之CBCGPTabWnd控件(相当于MFC TabControl)
随机推荐
Pointnet/Pointnet++点云数据集处理并训练
BCG 使用之CBCGPTabWnd控件(相当于MFC TabControl)
[QNX Hypervisor 2.2用户手册]6.3.1 工厂页和控制页
To sort out messy header files, I use include what you use
Shell programming core technology "three"
牛客小白月赛7 F题
如何使用Async-Awati异步任务处理代替BackgroundWorker?
添加命名空间声明
1002. A+B for Polynomials (25)(PAT甲级)
Pytest 可视化测试报告之 Allure
1006 Sign In and Sign Out(25 分)(PAT甲级)
92.(cesium篇)cesium楼栋分层
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
1011 World Cup betting (20 points) (pat a)
1006 sign in and sign out (25 points) (PAT class a)
明明的随机数
在线SQL转Excel(xls/xlsx)工具
kotlin 继承
联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点