当前位置:网站首页>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
边栏推荐
- uni-app 实现全局变量
- Introduction Guide to stereo vision (7): stereo matching
- Golang foundation - the time data inserted by golang into MySQL is inconsistent with the local time
- Programming implementation of ROS learning 5-client node
- 2309. 兼具大小写的最好英文字母
- Node collaboration and publishing
- 交通运输部、教育部:广泛开展水上交通安全宣传和防溺水安全提醒
- 生成对抗网络
- Alibaba cloud sends SMS verification code
- RT thread kernel quick start, kernel implementation and application development learning with notes
猜你喜欢
Applet (global data sharing)
Add discount recharge and discount shadow ticket plug-ins to the resource realization applet
Shutter uses overlay to realize global pop-up
Progressive JPEG pictures and related
Use and programming method of ros-8 parameters
Summary of "reversal" problem in challenge Programming Competition
Attention is all you need
Hi Fun Summer, play SQL planner with starrocks!
nodejs_ 01_ fs. readFile
Node collaboration and publishing
随机推荐
信息與熵,你想知道的都在這裏了
Ros-10 roslaunch summary
[Niuke brush questions day4] jz55 depth of binary tree
Applet network data request
Driver's license physical examination hospital (114-2 hang up the corresponding hospital driver physical examination)
嗨 FUN 一夏,与 StarRocks 一起玩转 SQL Planner!
.NET服务治理之限流中间件-FireflySoft.RateLimit
Rebuild my 3D world [open source] [serialization-1]
AUTOSAR from getting started to mastering 100 lectures (103) -dbc file format and creation details
Codeforces Round #648 (Div. 2) E.Maximum Subsequence Value
C # draw Bezier curve with control points for lattice images and vector graphics
[code practice] [stereo matching series] Classic ad census: (4) cross domain cost aggregation
AdaBoost use
Svgo v3.9.0+
3D reconstruction open source code summary [keep updated]
Confusing basic concepts member variables local variables global variables
Introduction Guide to stereo vision (3): Zhang calibration method of camera calibration [ultra detailed and worthy of collection]
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
File server migration scheme of a company
Creation and reference of applet