1. Basic type
Kotlin
With respect Java
for less, Java
in addition to the basic package as well as the type of class, but in Kotlin
the wrapper classes are
above picture is very obvious comparison here is not to say, if we say that the next in Kotlin
how to declare variable
1.1 Declare variables
In the kotlin
two variables are declared val
andvar
What is the difference between the two? That is to say, the val
declared variable cannot be changed when we use it below. It var
can be val
declared , and the declaration is similar Java
to the final
decoration in ours.As
we see in the figure below , oh, The Kolin
number of characters in a variable declared in is actually Java
more! Actually it is not, here we will say Kotlin
the type derivation in the next , the type of Kotlin
this variable can be derived from the value on the right side of the equal sign, so it is actually unnecessary for me to put Type it out, like the following
1.2 Long
Type tags that are confusing
In Java
declaring a Long
type of variable in, we usually add L
or after the value l
, but this l
is easily confused with uppercase I
or uppercase 1
, Kotlin
and it must be used L
in .You can l
not use lowercase to compile.
1.3 Numeric type conversion
In Java
we can assign a Int
type of variable to a Long
type of variable, just use the =
number, but Kotlin
it is not possible in the middle, we must call its conversion method.We
directly use the =
number compiler to directly prompt an error, then what should we do Do?
1.4 Unsigned types
There Java
is no one among us, but C
there is, and there is this type of Kotlin
compatibilityC
1.5 String
It's basically Java
the same as the one in here.
1.5.1 """ """
Declaration string
Kotlin
We can use three double quotes in the declaration string, what we declare here, what it prints
1.5.2 String templates
The string template starts with a dollar sign $
and contains any expressions in variable names or curly braces.
1.5.3 String comparison
Java
Use equals
and to compare two strings in ==
, kotlin
respectively corresponding to ==
and===