当前位置:网站首页>Kotlin variable
Kotlin variable
2022-07-05 12:42:00 【Curious rookie】
One 、 Variable definitions
/*
keyword Variable type
↓ ↓ */
var price: Int = 100; /*
↑ ↑
Variable name A variable's value */
In most cases , Variable types can be derived , It can be omitted ; Semicolons at the end are generally omitted ;
Two 、 The type of variable
package com.example.demo
fun main() {
// value type
val int = 1
val long = 1234567L
val double = 13.14
val float = 13.14F
val hexadecimal = 0xAF
val binary = 0b01010101
// toByte()、toShort()、toInt()、toLong()、toFloat()、toDouble()、toChar() Type conversion .
val j = int.toLong();
// Boolean type
val flag1 = true
val flag2 = false
println(flag1 && flag2)
// character
val c: Char = 'A'
// character string
val s = "Hello Kotlin!"
val name = "Kotlin"
print("Hello $name!") //Hello Kotlin!
val array = arrayOf("Java", "Kotlin")
print("Hello ${array.get(1)}!") //Hello Kotlin!
val s2 = """
When our string has a complex format
The original string is very convenient
Because it can do what you see is what you get . """
print(s2)
// Array
val arrayInt = arrayOf(1, 2, 3)
val arrayString = arrayOf("apple", "pear")
println(arrayInt.size) //3
}
3、 ... and 、 Air safety
val i: Double = null // Compiler error
Kotlin Developers are forced to define variables , Specifies whether this variable can be null. For possible null The variable of , We need to make a statement , Add a question mark after the variable type “?”
var i: Double = 1.0
var j: Double? = null
i = j // Compiler error
j = i // Compile and pass
边栏推荐
- MySQL installation, Windows version
- Pytoch through datasets Imagefolder loads datasets directly from files
- Database connection pool & jdbctemplate
- Understand redis persistence mechanism in one article
- How can beginners learn flutter efficiently?
- Kotlin函数
- GNN(pytorch-geometric)
- Redis cluster configuration
- Using docker for MySQL 8.0 master-slave configuration
- Hexadecimal conversion summary
猜你喜欢
UNIX socket advanced learning diary -ipv4-ipv6 interoperability
About cache exceptions: solutions for cache avalanche, breakdown, and penetration
Redis clean cache
Pytoch loads the initialization V3 pre training model and reports an error
MySQL index (1)
Add a new cloud disk to Huawei virtual machine
Redis highly available sentinel mechanism
Redis's memory elimination mechanism, read this article is enough.
Read and understand the rendering mechanism and principle of flutter's three trees
Flutter2 heavy release supports web and desktop applications
随机推荐
Ecplise development environment configuration and simple web project construction
MySQL function
Docker configures redis and redis clusters
Distributed solution - distributed lock solution - redis based distributed lock implementation
ZABBIX 5.0 - LNMP environment compilation and installation
Detailed structure and code of inception V3
[HDU 2096] 小明A+B
Preliminary exploration of basic knowledge of MySQL
Language model
Storage Basics
GPON technical standard analysis I
View and modify the MySQL data storage directory under centos7
Basic operations of MySQL data table, addition, deletion and modification & DML
Semantic segmentation experiment: UNET network /msrc2 dataset
Handwriting blocking queue: condition + lock
Anaconda creates a virtual environment and installs pytorch
MySQL transaction
ZABBIX customized monitoring disk IO performance
Kotlin变量
Learn the memory management of JVM 03 - Method area and meta space of JVM