当前位置:网站首页>Kotlin introductory notes (I) kotlin variables and non variables
Kotlin introductory notes (I) kotlin variables and non variables
2022-07-05 09:13:00 【Meng Meng Mu Xi】
Preface : This tutorial is best done with JAVA Study on the basis of
One 、 Variable
Kotlin Excellent type derivation mechanism
- val :(value Abbreviation ) Used to declare an immutable variable , This variable cannot be re assigned after the initial assignment , Corresponding Java Medium final Variable .
- var :(variable Abbreviation ) Used to declare a variable , This kind of variable can still be re assigned after the initial assignment , Corresponding Java Non - final Variable .
Such as :
fun main() {
val num = 666
println("num = " + num)
}there num It is automatically deduced into Int ( notes :kotlin Abandoned int, All use object data types Such as :Int)
however , If we delay the assignment of a variable ,kotlin You can't automatically deduce , We need to use the following method
Kotlin You can display declared variables
val num:Int = 10We explicitly declare variables num by Int type , here Kotlin Don't try type derivation anymore .
Java and Kotlin Data type comparison table
| Java Basic data type | Kotlin data type | Data type description |
|---|---|---|
int | Int | integer |
| long | Long | Long integer |
| short | Short | Short |
| float | Float | Single-precision floating-point |
| double | Double | Double precision floating point |
| boolean | Boolean | Boolean type |
| char | Char | Character |
| byte | Byte | Character |
Kotlin The small white , When learning the works of teacher Guolin , Take notes . If there are any mistakes, please point out ! Thank you for reading !
Reference resources :《 First line of code Android ( The third edition )》 --- Guo Lin
边栏推荐
- 迁移学习和域自适应
- 3D reconstruction open source code summary [keep updated]
- [technical school] spatial accuracy of binocular stereo vision system: accurate quantitative analysis
- Programming implementation of ROS learning 2 publisher node
- Generate confrontation network
- Driver's license physical examination hospital (114-2 hang up the corresponding hospital driver physical examination)
- Creation and reference of applet
- Newton iterative method (solving nonlinear equations)
- Codeworks round 638 (Div. 2) cute new problem solution
- 牛顿迭代法(解非线性方程)
猜你喜欢
![Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]](/img/7d/e7370e757c18b3dbb47e633703c346.jpg)
Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]

Programming implementation of ROS learning 5-client node

Ros- learn basic knowledge of 0 ROS - nodes, running ROS nodes, topics, services, etc

c语言指针深入理解
![Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]](/img/c4/27ae0d259abc4e61286c1f4d90c06a.png)
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]

什么是防火墙?防火墙基础知识讲解

Programming implementation of subscriber node of ROS learning 3 subscriber

Use and programming method of ros-8 parameters

Applet customization component

Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method
随机推荐
2011-11-21 training record personal training (III)
2310. 个位数字为 K 的整数之和
【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
Codeforces Round #648 (Div. 2) D. Solve The Maze
优先级队列(堆)
np. allclose
AdaBoost use
Kubedm series-00-overview
Jenkins Pipeline 方法(函数)定义及调用
Applet (use of NPM package)
uni-app 实现全局变量
520 diamond Championship 7-4 7-7 solution
. Net service governance flow limiting middleware -fireflysoft RateLimit
Huber Loss
Ministry of transport and Ministry of Education: widely carry out water traffic safety publicity and drowning prevention safety reminders
Applet network data request
[technical school] spatial accuracy of binocular stereo vision system: accurate quantitative analysis
Return of missing persons
Information and entropy, all you want to know is here
信息与熵,你想知道的都在这里了