当前位置:网站首页>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
边栏推荐
- Codeworks round 638 (Div. 2) cute new problem solution
- OpenFeign
- Newton iterative method (solving nonlinear equations)
- notepad++
- Programming implementation of ROS learning 2 publisher node
- Hosting environment API
- Nodejs modularization
- Nodemon installation and use
- 阿里云发送短信验证码
- Understanding rotation matrix R from the perspective of base transformation
猜你喜欢

22-07-04 西安 尚好房-项目经验总结(01)
![Introduction Guide to stereo vision (5): dual camera calibration [no more collection, I charge ~]](/img/68/6bfa390b0bedcdbc4afba2f9bd9c0f.jpg)
Introduction Guide to stereo vision (5): dual camera calibration [no more collection, I charge ~]
![[technical school] spatial accuracy of binocular stereo vision system: accurate quantitative analysis](/img/59/823b587566f812c76e0e4dee486674.jpg)
[technical school] spatial accuracy of binocular stereo vision system: accurate quantitative analysis

牛顿迭代法(解非线性方程)
![C [essential skills] use of configurationmanager class (use of file app.config)](/img/8b/e56f87c2d0fbbb1251ec01b99204a1.png)
C [essential skills] use of configurationmanager class (use of file app.config)

C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)
![Rebuild my 3D world [open source] [serialization-2]](/img/e6/aad5f432aca619b992753187729dcf.jpg)
Rebuild my 3D world [open source] [serialization-2]

Applet data attribute method

Summary and Reflection on issues related to seq2seq, attention and transformer in hands-on deep learning

Programming implementation of ROS learning 2 publisher node
随机推荐
Programming implementation of ROS learning 6 -service node
Multiple linear regression (sklearn method)
Programming implementation of ROS learning 2 publisher node
OpenFeign
Golang foundation -- map, array and slice store different types of data
Install the CPU version of tensorflow+cuda+cudnn (ultra detailed)
Applet (global data sharing)
Nodemon installation and use
驾驶证体检医院(114---2 挂对应的医院司机体检)
2011-11-21 training record personal training (III)
Wxss template syntax
AUTOSAR从入门到精通100讲(103)-dbc文件的格式以及创建详解
Ros-10 roslaunch summary
Luo Gu p3177 tree coloring [deeply understand the cycle sequence of knapsack on tree]
Codeworks round 681 (Div. 2) supplement
云计算技术热点
uni-app 实现全局变量
Solutions of ordinary differential equations (2) examples
C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)
Array, date, string object method