Kotlin
简介
Getting Started
Basic Syntax
Defining packages
Defining functions
Defining local variables
Comments
Using string templates
Using conditional expressions
Using nullable values and checking for null
Using type checks and automatic casts
Using a for loop
Using a while loop
Using when expression
Using ranges
Using collections
Idioms
Creating DTOs (POJOs/POCOs)
Default values for function parameters
Filtering a list
String Interpolation
Instance Checks
Traversing a map/list of pairs
Using ranges
Read-only list
Read-only map
Accessing a map
Lazy property
Extension Functions
Creating a singleton
If not null shorthand
If not null and else shorthand
Executing a statement if null 11
Execute if not null
Return on when statement
'try/catch' expression
'if' expression
Builder-style usage of methods that return Unit
Single-expression functions
Calling multiple methods on an object instance ('with')
Java 7's try with resources
Convenient form for a generic function that requires the generic type information
Consuming a nullable Boolean
Coding Conventions
Naming Style
Colon
Lambdas
Class header formatting
Unit
Functions vs Properties
What's New in Kotlin 1.1
Table of Contents
JavaScript
Coroutines (experimental)
Other Language Features
Type aliases
Bound callable references
Sealed and data classes
Destructuring in lambdas
Underscores for unused parameters
Underscores in numeric literals
Shorter syntax for properties
Inline property accessors
Local delegated properties
Interception of delegated property binding
Generic enum value access
Scope control for implicit receivers in DSLs
rem operator
Standard library
String to number conversions
onEach()
also(), takeIf() and takeUnless()
groupingBy()
Map.toMap() and Map.toMutableMap()
Map.minus(key)
minOf() and maxOf()
Array-like List instantiation functions
Map.getValue()
Abstract collections
Array manipulation functions
JVM Backend
Java 8 bytecode support
Java 8 standard library support
Parameter names in the bytecode
Constant inlining
Mutable closure variables
javax.script support
kotlin.reflect.full
JavaScript Backend
Unified standard library
Better code generation
The external modifier
Improved import handling
Basics
Basic Types
Numbers
Literal Constants
Underscores in numeric literals (since 1.1)
Representation
Explicit Conversions
Operations
Characters
Booleans
Arrays
Strings
String Literals
String Templates
Packages
Default Imports
Imports
Visibility of Top-level Declarations
Control Flow
If Expression
When Expression
For Loops
While Loops
Break and continue in loops
Returns and Jumps
Break and Continue Labels
Return at Labels
Classes and Objects
Classes and Inheritance
Classes
Constructors
Creating instances of classes
Class Members
Inheritance
Overriding Methods
Overriding Properties
Overriding Rules
Abstract Classes
Companion Objects
Properties and Fields
Declaring Properties
Getters and Setters
Backing Fields
Backing Properties
Compile-Time Constants
Late-Initialized Properties
Overriding Properties
Delegated Properties
Interfaces
Implementing Interfaces
Properties in Interfaces
Resolving overriding conflicts
Visibility Modifiers
Packages
Classes and Interfaces
Constructors
Local declarations
Modules
Extensions
Extension Functions
Extensions are resolved statically
Nullable Receiver
Extension Properties
Companion Object Extensions
Scope of Extensions
Declaring Extensions as Members
Motivation
Data Classes
Copying
Data Classes and Destructuring Declarations
Standard Data Classes
Sealed Classes
Relaxed Rules for Sealed Classes (since 1.1)
Subclasses in the Same File
Sealed Classes and Data Classes
Generics
Variance
Declaration-site variance
Type projections
Use-site variance: Type projections
Star-projections
Generic functions
Generic constraints
Upper bounds
Nested Classes
Inner classes
Anonymous inner classes
Enum Classes
Initialization
Anonymous Classes
Working with Enum Constants
Object Expressions and Declarations
Object expressions
Object declarations
Companion Objects
Semantic difference between object expressions and declarations
Delegation
Class Delegation
Delegated Properties
Standard Delegates
Lazy
Observable
Storing Properties in a Map
Local Delegated Properties (since 1.1)
Property Delegate Requirements
Translation Rules
Providing a delegate (since 1.1)
Functions and Lambdas
Functions
Function Declarations
Function Usage
Infix notation
Parameters
Default Arguments
Named Arguments
Unit-returning functions
Single-Expression functions
Explicit return types
Variable number of arguments (Varargs)
Function Scope
Local Functions
Member Functions
Generic Functions
Inline Functions
Extension Functions
Higher-Order Functions and Lambdas
Tail recursive functions
Higher-Order Functions and Lambdas
Higher-Order Functions
it: implicit name of a single parameter
Underscore for unused variables (since 1.1)
Destructuring in Lambdas (since 1.1)
Inline Functions
Lambda Expressions and Anonymous Functions
Function Types
Lambda Expression Syntax
Anonymous Functions
Closures
Function Literals with Receiver
Inline Functions
noinline
Non-local returns
Reified type parameters
Inline properties
Coroutines
Blocking vs Suspending
Suspending functions
@RestrictsSuspension annotation
The inner workings of coroutines
Experimental status of coroutines
Standard APIs
Low-level API: kotlin.coroutines
Generators API in kotlin.coroutines
Other high-level APIs: kotlinx.coroutines
Other
Destructuring Declarations
Example: Returning Two Values from a Function
Example: Destructuring Declarations and Maps
Underscore for unused variables (since 1.1)
Destructuring in Lambdas (since 1.1)
Collections
Ranges
How it works
Utility functions
rangeTo()
downTo()
reversed()
step()
Type Checks and Casts
is and !is Operators
Smart Casts
"Unsafe" cast operator
"Safe" (nullable) cast operator
This Expression
Qualified this
Equality
Referential equality
Structural equality
Operator overloading
Conventions
Unary operations
Binary operations
Infix calls for named functions
Null Safety
Nullable types and Non-Null Types
Checking for null in conditions
Safe Calls
Elvis Operator
The !! Operator
Safe Casts
Collections of Nullable Type
Exceptions
Exception Classes
Try is an expression
Checked Exceptions
The Nothing type
Java Interoperability
Annotations
Annotation Declaration
Usage
Constructors
Lambdas
Annotation Use-site Targets
Java Annotations
Reflection
Class References
Bound Class References (since 1.1)
Function References
Example: Function Composition
Property References
Interoperability With Java Reection
Constructor References
Bound Function and Property References (since 1.1)
Type-Safe Builders
A type-safe builder example
How it works
Scope control: @DslMarker (since 1.1)
Full definition of the com.example.html package
Type aliases
Reference
Grammar
Notation
Symbols and naming
EBNF expressions
Semicolons
Syntax
Classes
Class members
Enum classes
Types
Control structures
Expressions
Precedence
Rules
Modifiers
Annotations
Lexical structure
Compatibility
Compatibility glossary
Compatibility guarantees for Kotlin releases
Compatibility across platforms
Experimental features
EAP builds
Compatibility modes
Binary compatibility warnings
Java Interop
Calling Java code from Kotlin
Getters and Setters
Methods returning void
Escaping for Java identifiers that are keywords in Kotlin
Null-Safety and Platform Types
Notation for Platform Types
Nullability annotations
Mapped types
Java generics in Kotlin
Java Arrays
Java Varargs
Operators
Checked Exceptions
Object Methods
wait()/notify()
getClass()
clone()
finalize()
Inheritance from Java classes
Accessing static members
Java Reflection
SAM Conversions
Using JNI with Kotlin
Calling Kotlin from Java
Properties
Package-Level Functions
Instance Fields
Static Fields
Static Methods
Visibility
KClass
Handling signature clashes with @JvmName
Overloads Generation
Checked Exceptions
Null-safety
Variant generics
Translation of type Nothing
JavaScript
Kotlin JavaScript Overview
How can it be used
Getting Started with Kotlin to JavaScript
Dynamic Type
Calling JavaScript from Kotlin
Inline JavaScript
external modifier
Declaring (static) members of a class
Declaring optional parameters
Extending JavaScript classes
external interfaces
Calling Kotlin from JavaScript
Isolating declarations in a separate JavaScript object
Package structure
@JsName annotation
Representing Kotlin types in JavaScript
JavaScript Modules
Choosing the Target Module System
From IntelliJ IDEA
From Maven
From Gradle
@JsModule annotation
Applying @JsModule to packages
Importing deeper package hierarchies
@JsNonModule annotation
Notes
JavaScript Reflection
JavaScript Modules
JavaScript Reflection
Tools
Documenting Kotlin Code
Generating the Documentation
KDoc Syntax
Block Tags
@param
@return
@constructor
@receiver
@property
@throws
, @exception
@sample
@see
@author
@since
@suppress
Inline Markup
Linking to Elements
Module and Package Documentation
Using Gradle
Plugin and Versions
Targeting the JVM
Targeting JavaScript
Targeting Android
Android Studio
Configuring Dependencies
Annotation processing
Incremental compilation
Coroutines support
Compiler Options
Attributes common for JVM and JS
Attributes specific for JVM
Attributes specific for JS
OSGi
Examples
Using Maven
Plugin and Versions
Dependencies
Compiling Kotlin only source code
Compiling Kotlin and Java sources
Jar file
Self-contained Jar file
Targeting JavaScript
Specifying compiler options
Attributes common for JVM and JS
Attributes specific for JVM
Attributes specific for JS
Generating documentation
OSGi
Examples
Using Ant
Getting the Ant Tasks
Targeting JVM with Kotlin-only source
Targeting JVM with Kotlin-only source and multiple roots
Targeting JVM with Kotlin and Java source
Targeting JavaScript with single source folder
Targeting JavaScript with Pre..x, PostFix and sourcemap options
Targeting JavaScript with single source folder and metaInfo option
References
Attributes common for kotlinc and kotlin2js
kotlinc Attributes
kotlin2js Attributes
Kotlin and OSGi
Maven
Gradle
FAQ
Compiler Plugins
All-open compiler plugin
How to use all-open plugin
Kotlin-spring compiler plugin
No-arg compiler plugin
How to use no-arg plugin
Kotlin-jpa compiler plugin
FAQ
FAQ
Common Questions
What is Kotlin?
Why a new language?
How is it licensed?
Where can I get an HD Kotlin logo?
Is it Java Compatible?
Which minimum Java version is required for running Kotlin code?
Is there tooling support?
Is there Eclipse support?
Is there a standalone compiler?
Is Kotlin a Functional Language?
Does Kotlin support generics?
Are semicolons required?
Why have type declarations on the right?
Will right-handed type declarations affect tooling?
Is Kotlin extensible?
Can I embed my DSL into the language?
What ECMAScript level does Kotlin for JavaScript support
Does the JavaScript back-end support module systems?
Comparison to Java
Some Java issues addressed in Kotlin
What Java has that Kotlin does not
What Kotlin has that Java does not
Comparison to Scala
What Scala has that Kotlin does not
What Kotlin has that Scala does not
Powered by
GitBook
Compiler Plugins
编译插件
请继续查看以下的内容。
results matching "
"
No results matching "
"