当前位置:网站首页>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 = 10
We 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
边栏推荐
- [code practice] [stereo matching series] Classic ad census: (6) multi step parallax optimization
- Summary of "reversal" problem in challenge Programming Competition
- C # draw Bezier curve with control points for lattice images and vector graphics
- Applet (subcontracting)
- 信息與熵,你想知道的都在這裏了
- Ministry of transport and Ministry of Education: widely carry out water traffic safety publicity and drowning prevention safety reminders
- Composition of applet code
- Use arm neon operation to improve memory copy speed
- Ros- learn basic knowledge of 0 ROS - nodes, running ROS nodes, topics, services, etc
- Blue Bridge Cup provincial match simulation question 9 (MST)
猜你喜欢
Programming implementation of ROS learning 5-client node
Information and entropy, all you want to know is here
C [essential skills] use of configurationmanager class (use of file app.config)
Introduction Guide to stereo vision (2): key matrix (essential matrix, basic matrix, homography matrix)
Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method
Applet global style configuration window
Introduction Guide to stereo vision (4): DLT direct linear transformation of camera calibration [recommended collection]
信息與熵,你想知道的都在這裏了
Priority queue (heap)
Applet (global data sharing)
随机推荐
c语言指针深入理解
c#比较两张图像的差异
nodejs_ fs. writeFile
[Niuke brush questions day4] jz55 depth of binary tree
Generate confrontation network
nodejs_ 01_ fs. readFile
Mengxin summary of LCs (longest identical subsequence) topics
np.allclose
Talking about label smoothing technology
uni-app 实现全局变量
scipy. misc. imread()
AUTOSAR从入门到精通100讲(103)-dbc文件的格式以及创建详解
Creation and reference of applet
信息與熵,你想知道的都在這裏了
2311. 小于等于 K 的最长二进制子序列
. Net service governance flow limiting middleware -fireflysoft RateLimit
Svgo v3.9.0+
阿里云发送短信验证码
[beauty of algebra] singular value decomposition (SVD) and its application to linear least squares solution ax=b
Wxss template syntax