当前位置:网站首页>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
边栏推荐
- np. allclose
- Attention is all you need
- . Net service governance flow limiting middleware -fireflysoft RateLimit
- Newton iterative method (solving nonlinear equations)
- 【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
- Driver's license physical examination hospital (114-2 hang up the corresponding hospital driver physical examination)
- fs. Path module
- np.allclose
- Golang foundation -- map, array and slice store different types of data
- [technical school] spatial accuracy of binocular stereo vision system: accurate quantitative analysis
猜你喜欢
【ManageEngine】如何利用好OpManager的报表功能
Introduction Guide to stereo vision (4): DLT direct linear transformation of camera calibration [recommended collection]
Hosting environment API
[technical school] spatial accuracy of binocular stereo vision system: accurate quantitative analysis
Applet (global data sharing)
22-07-04 西安 尚好房-项目经验总结(01)
Solution to the problems of the 17th Zhejiang University City College Program Design Competition (synchronized competition)
Programming implementation of ROS learning 2 publisher node
Blogger article navigation (classified, real-time update, permanent top)
Use and programming method of ros-8 parameters
随机推荐
Transfer learning and domain adaptation
Return of missing persons
[technical school] spatial accuracy of binocular stereo vision system: accurate quantitative analysis
Svg optimization by svgo
22-07-04 西安 尚好房-项目经验总结(01)
云计算技术热点
C # image difference comparison: image subtraction (pointer method, high speed)
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition
编辑器-vi、vim的使用
notepad++
Applet data attribute method
Meta tag details
混淆矩阵(Confusion Matrix)
The combination of deep learning model and wet experiment is expected to be used for metabolic flux analysis
np.allclose
Applet (subcontracting)
Global configuration tabbar
[beauty of algebra] singular value decomposition (SVD) and its application to linear least squares solution ax=b
信息與熵,你想知道的都在這裏了
C # draw Bezier curve with control points for lattice images and vector graphics