Title | Kotlin Docs |
---|---|
Tags | Class (Computer Programming) Inheritance (Object Oriented Programming) Constructor (Object Oriented Programming) Anonymous Function Method (Computer Programming) |
File Size | 809.5 KB |
Total Pages | 151 |
Table of Contents 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 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 Coding Conventions Naming Style Colon Lambdas Unit Functions vs Properties Basics Basic Types Numbers Literal Constants Representation Explicit Conversions Operations Characters Booleans Arrays Strings String Literals String Templates Packages 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 Members Overriding Rules Abstract Classes Companion Objects Sealed Classes 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 Generics Variance Declaration-site variance Type projections Use-site variance: Type projections Star-projections Generic functions Generic constraints Upper bounds Nested Classes 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 Property Delegate Requirements Standard Delegates Lazy Observable Storing Properties in a Map 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 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 Other Destructuring Declarations Example: Returning Two Values from a Function Example: Destructuring Declarations and Maps 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 Exceptions Exception Classes Try is an expression Checked Exceptions Java Interoperability Annotations Annotation Declaration Usage Constructors Lambdas Annotation Use-site Targets Java Annotations Reflection Class References Function References Example: Function Composition Property References Interoperability With Java Reflection Constructor References Type-Safe Builders A type-safe builder example How it works Full definition of the com.example.html package Dynamic Type Reference 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 Handling signature clashes with @JvmName Overloads Generation Checked Exceptions Null-safety Variant generics Translation of type Nothing Tools Documenting Kotlin Code Generating the Documentation KDoc Syntax Block Tags @param <name> @return @constructor @property <name> @throws <class>, @exception <class> @sample <identifier> @see <identifier> @author @since @suppress Inline Markup Linking to Elements Using Maven Plugin and Versions Dependencies Compiling Kotlin only source code Compiling Kotlin and Java sources 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 Prefix, PostFix and sourcemap options Targeting JavaScript with single source folder and metaInfo option References Attributes common for kotlinc and kotlin2js kotlinc Attributes kotlin2js Attributes Using Gradle Plugin and Versions Targeting the JVM Targeting JavaScript Targeting Android Android Studio Configuring Dependencies OSGi Examples Kotlin and OSGi Maven Gradle FAQ Why not just add required manifest options to all Kotlin libraries FAQ FAQ Common Questions What is Kotlin? Why a new language? How is it licensed? 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? Are curly braces 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 the 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