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
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 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
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
These days have been preparing for the exam, really no time, has passed so long, finally to the object-oriented!Let's see what the Kotlin in the class look like.Can see Kotlin in the class is still very common, mostly similar to Java, the more special are:Each constructor must have an initial value assigned to each member variable.Primary constructor, the head of this constructor is immediately following th
Arc Menu 2 (animation fade-in +kotlin development)Preface: A curved menu based on Androidstudio, which is developed using the Kotlin language, and the animation is gradually entered ...Effect:Development environment: androidstudio2.2.1+gradle-2.14.1Knowledge Involved: 1. Custom controls, 2. Event distribution, etc.Part of the code:Activity:classhomepageactivity:appcompatactivity () {Privatevar homepagemenul
Keywords in kotlin that are consistent with Java usage include: override, while declarations
· Open in Kotlin a class needs to be inherited by another class, you need to use the Open keyword
Open Class Openclass {}
· is judgment type
Fun testis () {
var a:any? = null;
A = 3L
if (A is int) {
println (' A is int ')
} else if (A is long) {
println ('
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
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
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)
}
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
Annotation definition Annotations
Annotation Class Fancy
constructor for annotations
can take parameters
Annotation Class Special (Val why:string)
Special ("Example") class Foo {}
using Annotations
@fancy class Foo {
@fancy fun baz (@fancy foo:int): Int {
return 1
}
}
annotations in the main constructor
Class Foo @inject Constructor (dependency:mydependency)
annotations in property visitors
Class Foo {
var x:mydependency?=null
@inject Set
}
annotations in
The Magical Wuhan University International Software College, only freshman will attend summer training, now sophomore, examination to 7.9, more than 20 days of the end of the training, and then a few days, but also early to school, poor my summer vacation so no.Then say Kotlin:First look at a class named messageIn this class there is a section of code contained in the companion object, it should be said that the Kotlin class does not support the stati
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
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.