Kotlin recently is a fire, so want to try, of course, IntelliJ is very useful, but open a bit slow, for me this just touch kotlin small white ... (I was impatient 0.0.)
So think or try to be able to use sublime text directly compiled run, words not much to say, directly on dry:
I have already installed the Java environment by default.
1. The first step is to download ko
For details about the if, when, and while statements of kotlin, kotlinwhileIntroduction
Kotlin andLike Java, they all have their own process control statements, such as branch statements, loop statements, and jump statements. The difference between the two is not great,Relative to kotlinJava Process Control statements are more flexible and powerful.
if
If-else statement, representingIf conditions are met,
Kotlin operator overload: add standard operations to any class (KAD 17), kotlinkad
By Antonio Leiva
Time: Mar 21,201 7
Link: https://antonioleiva.com/operator-overload-kotlin/
Like other languages, some operators have been predefined in Kotlin to perform certain operations.
The most typical examples are addition (+), subtraction (-), multiplication (*), Divisi
Use of the when expression in Kotlin: super powerful switch (KAD 13) and kotlinkad
By Antonio Leiva
Time: Feb 23,201 7
Link: https://antonioleiva.com/when-expression-kotlin/
In Java (especially Java 6), switch expressions have many restrictions. Except for the short type, it basically cannot do anything else.
However, the when expression in Kotlin can do ever
Kotlin is a concise encapsulation of Java and provides a lot of convenient syntaxes. After skilled use, it will greatly reduce the number of lines of code and increase the encoding speed.For details about the advantages and disadvantages of kotlin, there are a lot of comments on the Internet. If you are interested, let's start our simple demo development.Requirement: the simplest crud for users, providing r
Antonio LeivaTime:Mar 9,Original link:https://antonioleiva.com/dialogs-android-anko-kotlin/with Builder, creating warning tips and dialogs on Android is relatively simple, but because of the complexity of the language, some hints often become very vague. in the in Kotlin, only Lambda Expressions can help us understand a little bit about how the code is handled. However, with the Anko, we can make it
Kotlin Object expressions and object declarations
Kotlin uses object expressions and object declarations to create an object that makes a minor change to a class, and does not need to declare a new subclass.The object in this article is a keyword, and note that there is no capitalization. I. Object expression 1. Objects that implement an anonymous inner class through an object expression are used in the pa
Kotlin plugin contains an interesting feature that can turn Java code into Kotlin code.So we use it in the Mainactivity.java class. Open the file, and then select Code-> Convert Java file to Kotlin file. The difference between them will make you more familiar with the language.
CTRL + SHIFT + A shortcut key input convert Java file to
function
Kotlin, a function is defined using the Fun keyword, and the function parameter is defined by the Pascal notation, which is name:type. Parameters are separated by commas. Each parameter must have an explicit type.
Fun foo (arg1:string,arg2:boolean,arg3:int): int{
//do somethong
return 1
}
When a function has only a single expression, you can omit the curly braces, write directly after =, or omit the return value type if the return va
Original link: Https://github.com/EasyKotlin
In the common concurrency model, multi-process, multi-threading, and distributed are the most common, but in recent years there are some languages that provide support for the concurrent-based concurrency model in the form of first-class or library. Some of the more typical scheme, Lua, Python, Perl, go and so on in the first-class way to provide support for the co-process.
Similarly, Kotlin also supports t
Kotlin official website:https://kotlinlang.orgwe can get from GitHub Download . Currently The latest version is 1.1.2-5Https://github.com/JetBrains/kotlin/releases/tag/v1.1.2-5Pull down below and you can seeAfter downloading the extract, add the bin directory inside the path of the system environment variable, you can. Of course, the premise is that the system has built a Java environmentCMD input kotlinc-
Associated Objects
analogy Java
Do you still remember static statically members in Java? Attributes and methods declared as static idioms are initialized at class loading, parsing, and then their lifecycle is bound to the life cycle of the class.
1. This allows certain variables and methods in a class to be bound to the class, rather than bound to an object, to increase its life cycle.
2. This allows objects of this class to share this variable and method without allocating resources for eac
In Kotlin, we can compose an object into multiple variables:
Data class Person
(Val name:string= "Kotlin", Val sex:string= "man", Val age:int=1)
Fun foo () {
var (name, Sex,age) =person ()//Deconstruction Declaration
print ("Name= $name sex= $sex age= $age")
}
This is the deconstruction declaration. A destructor declaration can declare multiple variables at once, and any expression can appear on t
The most basic use of an enumeration class is to implement type-safe enumerations
Enum class Direction {North
, SOUTH, West, East
}
Kotlin
Each enumerated constant is an object. Enumeration constants are separated by commas. Class
Because each enumeration is an instance of an enumeration class, they can be initialized.
Enum Class Color (Val rgb:int) {
RED (0xff0000),
GREEN (0x00ff00),
BLUE (0x0000ff)
}
Lambda with receiver* A method in the body of a lambda function that can invoke a different object without any additional qualifiers, which is not found in Java.* Such lambda is called "Lambda with receiver"Let's start with a normal function as a counter-example:Fun Alphabet (): String { val result = StringBuilder () for (letter in ' A ' ... ') Z ') { result.append (letter) } result.append ("\nnow, I know the alphabet") return result.tostring ()}In the above example, you ca
Kotlin Extension
Kotlin can extend the properties and methods of a class and do not need to inherit.An extension is a static behavior that does not have any effect on the extended class code itself.
Extension of the class, what a ghost. Anyway, I have never seen Java, the following look at the expansion of the Kotlin bar. I. Extension methods
is to add a method.
Kotlin Object expressions and object declarations
Kotlin uses object expressions and object declarations to implement an object that creates a class that makes minor changes to a class, and does not need to declare a new subclass. an object expression
An object that implements an anonymous inner class through an object expression is used in the parameters of the method:
Window.addmouselistener (Object:mous
Kotlin's control flow is the same as in other languages, order, branching, loopingThere are two types of branching, if-else and when (similar to switch in Java).If statement:Operation Result:The case statement in Java not only supports integer values, the latest JVM also supports strings, kotlin when statements are more powerful, switch variables can even be various types such as Double,array, in other words when statements are more powerful than swit
node of the layout file adds a custom namespace declaration, such as "xmlns:app=" Http://schemas.android.com/apk/res-auto "" and change the Android.support.v4.view.PagerTabStrip node name to the full path name of the custom view, such as "Com.example.custom.widget.PagerTab", At the same time, the new two attributes, App:textcolor and app:textsize, are specified under this node. The layout file code after the modification is as follows: The three steps of the custom attribute above, where the se
Forward pushDesign PatternsSimple Factory mode (Java and Kotlin Edition)Kotlin Basic KnowledgeKotlin first lesson: Starting with Java comparisonKotlin Introductory Lesson II: Collection OperationsKotlin Introductory Lesson Three: Data typesFirst attempt to implement Android projects with Kotlin1. DefinitionThe factory method pattern (Factory mode), also known as the factory pattern, is called the virtual Co
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.