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
constructors, destructors, and assignment functions are the most basic functions of each class. They are so common that they are easy to careless, but these seemingly simple functions are as dangerous as a sewer without a lid.Each class has only one destructor and one assignment function, but it can have multiple constructors (one copy constructor, others called ordinary
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
then copy the value of the temporary object to the new object by assigning a value. That is, initialization always invokes the copy constructor, and the assignment operator may be called when using the = operatorThe instance code is as follows:#include using namespacestd;classtest{ Public: Test (); ~Test (); Test (Consttestt); Testoperator=(Consttestt);Private: intT1;}; Test::test () {cout"Call Constructor"Endl;} Test::~Test () {cout"Call destructor"Endl;} Test::test (Consttestt) {cout"Call
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)
}
Analysis of these two usages, really want to spit groove Two, these two features do have actual needs, but objectively speaking, the existing standard is enough, and the cost is very large, but also to C + + complex syntax sugar to erase a lot!!!First, inherit the constructor functionThe reason for the introduction of the inherited constructor: if the constructor of the base class is many, then the constructor of the subclass wants to implement the same many construction interfaces, it must be o
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
(Refer to the in-depth understanding of the C + + object model)"There are two common misconceptions about C + + newbies:Any class that does not have a default constructor defined will be synthesized.The default constructor compiled by the compiler will explicitly set the defaults for each data member in the class. "Now the main explanation is why the first one is wrong, according to the "in-depth understanding of the C + + object Model", "default constructor is generated by the compiler when nee
For the relationship between such a class and class, we want to write a "deep copy" for it. The two classes are defined as follows:class Point { int x; int y;}; class Public Shape { *points;};1. Constructors// constructor Function Polygon (const point p): _point (new point ) { this->_point->x = p.x; This->_point->y = p.y;}2. Copy Constructors// Copy Construction Polygon (const Polygon p): _po
Constructors call constructors are problematic.The memory returned by the outer function, and the memory returned by the called constructor, is not a memory.The error sample code is as follows:Msg_log (Const Char*name,Const Char* Thread_name,Const Char*cfg_file,intType = STREAM,intLevel =msg_error): _name (name), _thread_name (Thread_name), _level (level), _type (type), LOGFP (0), _set_process (false), _set
Using Anko and Kotlin to develop databases on Android: SQLite is never an easy task (KAD25). ankokotlin
By Antonio Leiva
Time: Mar 30,201 7
Link: https://antonioleiva.com/databases-anko-kotlin/
The fact tells us that writing a database in Android is quite boring.
When using SQLite, all the required templates are not the most pleasant thing in the world today.
Fortunately, one of the items they announce
Getting Started Guide basic syntax definition packageThe declaration of the package must be at the top of the source file:Package My.demoImport java.util.*Java different packages do not have to match the directory structure: the source files can be placed anywhere on the file system.function definitionHere is an example of a parameter with two int types and an int return value:Fun sum (A:int, b:int): Int {Return a + b}Using an expression as a function body compiler can automatically infer the re
Examples of Spring Boot and Kotlin scheduled Tasks (Scheduling Tasks) and kotlinscheduling
You may encounter such scenarios when writing Spring Boot applications. For example, you need to regularly send text messages, emails, and other operations, and you may also regularly check and monitor some labels and parameters.
Create scheduled task
Writing a scheduled task in Spring Boot is very simple. The following describes how to create a scheduled task i
function
function Declaration
Functions in Kotlin Use the FUN keyword declaration
Fun double (x:int): Int {
}
function Usage
Calling a function using the traditional method
Val result = double (2)
Call member functions using dot notation
Sample (). Foo ()//Create class sample instance and call Foo
infix notation
Functions can also be called with infix notation when they are member functions or extension functions they have only one parameter
Before you read the following, you may need to understand some of the features of the Kotlin language: At the end of a statement, you can declare a method with the Fun keyword, and if the function is a method that overloads the parent class, you must also add the Override keyword. The parameter of the method is the first-write parameter name followed by the colon-and-write parameter type; The Kotlin source
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
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.