Index
Symbols
- ! (not operator), Not equals (!= and !), Where to use the is operator
- !! (not-null assertion operator), The !! operator deliberately throws a NullPointerException
- != (not equals operator), Not equals (!= and !), How to access a nullable type’s functions and properties
- $ (String template), Add the code to PhraseOMatic.kt
- && (and operator), We need to validate the user’s input, Where to use the is operator, How to access a nullable type’s functions and properties
- () (parentheses)
- * (spread operator), 9. More fun with functions
- ++ (increment operator), How for loops work, 8. Return, break and continue
- , (separator), You can send more than one thing to a function
- -- (decrement operator), How for loops work
- -> (separator), What lambda code looks like
- . (dot operator), We need to convert the value, How to access properties and functions, How to write a custom setter, Which function is called?
- .. (range operator), How for loops work
- // (comment), Anatomy of the main function, What can you say in the main function?
- : (name/type separator), How to explicitly declare a variable’s type, How a subclass inherits from a superclass, How to implement an abstract class, Declare that a class implements an interface...
- < (less than operator), Loop and loop and loop...
- <= (less than or equal to operator), Loop and loop and loop...
- <> (generics), The compiler infers the array’s type from its values, Collections use generics
- = (equals operator), Loop and loop and loop...
- == (equality operator)
- === (referential equality operator), ...that let you destructure data objects, How a Set checks for duplicates
- > (greater than operator), Loop and loop and loop...
- >= (greater than or equal to operator), Loop and loop and loop...
- ? (nullable type), You can use a nullable type everywhere you can use a non-nullable type
- ?. (safe call operator), Keep things safe with safe calls, Use let to run code if values are not null
- ?: (Elvis operator), Instead of using an if expression...
- @ (annotation/label), Create a JUnit test class, 8. Return, break and continue
- @JvmOverloads annotation, Test drive
- @Test annotation, Create a JUnit test class
- {} (curly braces)
- || (or operator), We need to validate the user’s input, Where to use the is operator
A
- abstract classes
- abstract functions
- abstract keyword, Some classes shouldn’t be instantiated, An abstract class can have abstract properties and functions, Let’s define the Roamable interface
- abstract properties
- abstract superclasses, Some classes shouldn’t be instantiated, How to implement an abstract class
- accessors (getters), How do you validate property values?, Overriding properties lets you do more than assign default values, You MUST implement all abstract properties and functions, How to define interface properties
- actions, Create a JUnit test class
- add() function
- addAll() function
- and operator (&&), We need to validate the user’s input, Where to use the is operator, How to access a nullable type’s functions and properties
- Android devices, It’s crisp, concise and readable
- angle brackets <>, The compiler infers the array’s type from its values, Collections use generics
- annotations/labels (@), Create a JUnit test class, 8. Return, break and continue
- Any superclass, equals is inherited from a superclass named Any, A data class lets you create data objects, Test drive, How to create an array of nullable types
- applications, building (see building applications)
- arguments
- Array class, Store multiple values in an array, Use downTo to reverse the range, Arrays can be useful..., Test drive
- Array<Type> type, The compiler infers the array’s type from its values
- arrayListOf() function, Test drive
- arrayOf() function, Store multiple values in an array, Get the game to choose an option, When you call a function on the variable, it’s the object’s version that responds, Arrays can be useful...
- arrayOfNulls() function, Arrays can be useful...
- arrays
- building applications using, Create the Phrase-O-Matic application
- creating, Store multiple values in an array, Get the game to choose an option
- declaring, var means the variable can point to a different array
- evaluating, Add the code to PhraseOMatic.kt
- explicitly defining type, The compiler infers the array’s type from its values
- inferring type from values, The compiler infers the array’s type from its values
- limitations of, ...but there are things an array can’t handle
- looping through items in, Use downTo to reverse the range
- object references and, Store multiple values in an array, The compiler infers the array’s type from its values, Behind the scenes: what happens
- of nullable types, How to create an array of nullable types, ...but there are things an array can’t handle
- starting index value, Store multiple values in an array
- storing values in, Store multiple values in an array
- ways to use, Arrays can be useful...
- as operator, Use as to perform an explicit cast, An exception is an object of type Exception, The fully qualified name
- assertEquals assertion, Create a JUnit test class
- assertion operators, The !! operator deliberately throws a NullPointerException
- assertions, Create a JUnit test class
- assignment operators, Loop and loop and loop...
- asynchronous execution, Test drive
- attributes (objects) (see properties)
- average() function (Array), Arrays can be useful...
B
- backing fields, How to write a custom setter, How to define interface properties
- base classes (see superclasses)
- behavior (objects), We need to convert the value, Use inheritance to avoid duplicate code in subclasses, We can group some of the animals
- binary numbers, Integers
- Boolean expressions, We need to validate the user’s input
- Boolean tests, simple, Loop and loop and loop...
- Boolean type, Booleans
- break statement, 8. Return, break and continue
- building applications
- built-in higher-order functions
- about, built-in higher-order functions: Power Up Your Code
- filter() function, Kotlin has a bunch of built-in higher-order functions, Meet the filter function
- filterIsInstance() function, Meet the filter function
- filterNot() function, Meet the filter function, The story continues...
- filterTo() function, Meet the filter function, The story continues...
- fold() function, How to use the fold function, Test drive
- foldRight() function, Test drive
- forEach() function, forEach works like a for loop, You can use groupBy in function call chains, Test drive
- groupBy() function, Use groupBy to split your collection into groups
- map() function, Use map to apply a transform to your collection
- max() function, The min and max functions work with basic types
- maxBy() function, The min and max functions work with basic types
- min() function, The min and max functions work with basic types
- minBy() function, The min and max functions work with basic types
- reduceRight() function, Test drive
- sumBy() function, The sumBy and sumByDouble functions
- sumByDouble() function, The sumBy and sumByDouble functions
- Byte type, Integers
C
- capitalize() function, Add the printResult function to Game.kt
- casting, The is operator usually performs a smart cast, An exception is an object of type Exception
- catch block (try/catch), Catch exceptions using a try/catch, You can explicitly throw exceptions
- catching exceptions, An exception is thrown in exceptional circumstances
- Char type, Booleans
- characteristics (objects) (see properties)
- characters (type), Booleans
- class keyword, Let’s define a Dog class
- ClassCastException, An exception is an object of type Exception
- classes
- about, classes and objects: A Bit of Class
- abstract, Some classes shouldn’t be instantiated
- adding to projects, We’ll create some Kotlin animals, Add the Canine and Wolf classes
- as templates, classes and objects: A Bit of Class, How to create a Dog object, How do you know whether to make a class, a subclass, an abstract class, or an interface?
- building, We’ll create some Kotlin animals
- common protocols for, Inheritance guarantees that all subclasses have the functions and properties defined in the superclass, Test drive, The Animal class hierarchy revisited, The Animal class has two abstract functions, Let’s define the Roamable interface
- concrete, Abstract or concrete?, You MUST implement all abstract properties and functions, Declare that a class implements an interface..., The compiler can infer the generic type
- data (see data classes)
- defining, Object types are defined using classes
- defining properties in main body, Flexible property initialization
- defining without constructors, You MUST initialize your properties
- designing, How to design your own classes
- enum, 3. Enum classes
- generics and, Things you can do with a generic class or interface, Test drive, Use out to make a generic type covariant, We need a Vet class, Use in to make a generic type contravariant
- inheritance (see inheritance)
- inner, An inner class can access the outer class members
- member functions and, Let’s define a Dog class, How to access properties and functions
- nested, 5. Nested and inner classes
- outer, 5. Nested and inner classes
- prefixing with open, Declare the superclass and its properties and functions as open, Overriding properties lets you do more than assign default values
- sealed, 4. Sealed classes
- subclasses (see subclasses)
- superclasses (see superclasses)
- tips when creating, How do you know whether to make a class, a subclass, an abstract class, or an interface?
- visibility modifiers and, Visibility modifiers and classes/interfaces
- clear() function
- closure (lambdas), forEach has no return value, Test drive
- code editors, Install IntelliJ IDEA (Community Edition), Add the main function to App.kt
- Collection interface, Test drive
- collections
- about, Test drive
- arrays and, Arrays can be useful...
- generics and, Collections use generics, Add the scores property
- higher-order functions and, Kotlin has a bunch of built-in higher-order functions, Meet the filter function, Use groupBy to split your collection into groups, Test drive
- Kotlin Standard Library, When in doubt, go to the Library
- List interface, List, Set and Map, Lists allow duplicate values, Test drive
- Map interface, List, Set and Map, Time for a Map
- MutableList interface, List, Set and Map, Create a MutableList..., Lists allow duplicate values, How a MutableList is defined, The compiler can infer the generic type
- MutableMap interface, List, Set and Map, Create a MutableMap, Add the scores property
- MutableSet interface, List, Set and Map, How to create a Set, How to use a MutableSet, Create the getWinners function
- Set interface, List, Set and Map, How to create a Set, Test drive, Test drive
- colon (:), How to explicitly declare a variable’s type, How a subclass inherits from a superclass, How to implement an abstract class, Declare that a class implements an interface...
- comma (,), You can send more than one thing to a function
- comments, forward slash and, Anatomy of the main function, What can you say in the main function?
- companion keyword, Class objects...
- Comparable interface, A closer look at minBy and maxBy’s lambda parameter
- comparison operators, Loop and loop and loop..., == calls a function named equals, The common behavior defined by Any, ...that let you destructure data objects
- componentN functions, Data classes define componentN functions...
- concrete classes, Abstract or concrete?, You MUST implement all abstract properties and functions, Declare that a class implements an interface..., The Retailer hierarchy
- concrete functions, Let’s define the Roamable interface
- conditional branching
- conditional tests, Loop and loop and loop...
- configuring projects, 3. Configure the project
- constants
- constructor keyword, 2. Using named arguments
- constructors
- @JvmOverloads annotation, Test drive
- about, How objects are created
- defining classes without, You MUST initialize your properties
- defining properties, Behind the scenes: calling the Dog constructor, Behind the scenes: calling the Dog constructor, Generated functions only use properties defined in the constructor
- empty, You MUST initialize your properties
- enum classes and, 3. Enum classes
- generics and, Create Vet objects
- primary (see primary constructors)
- secondary, 2. Using named arguments, Test drive
- visibility modifiers, Visibility modifiers and classes/interfaces
- with default values, How to use a constructor’s default values
- contains() function
- containsKey() function (Map), How to use a Map
- containsValue() function (Map), How to use a Map
- continue statement, 8. Return, break and continue
- contravariant generic types, Use in to make a generic type contravariant, Test drive
- conversion functions, We need to convert the value
- converting values, We need to convert the value
- copy() function, Copy data objects using the copy function, Test drive
- coroutines
- covariant generic types, Use out to make a generic type covariant, Test drive
- creating
- abstract classes, How do you know whether to make a class, a subclass, an abstract class, or an interface?
- arrays, Store multiple values in an array, Get the game to choose an option
- exceptions, An exception is an object of type Exception
- functions, How you create functions
- interfaces, How do you know whether to make a class, a subclass, an abstract class, or an interface?
- objects, How to create a Dog object, The miracle of object creation, A data class lets you create data objects
- projects, Java Virtual Machines (JVMs), Let’s build a basic application, Here’s what we’re going to do
- subclasses, How do you know whether to make a class, a subclass, an abstract class, or an interface?
- variables, Your code needs variables
- curly braces {}
- custom getters/setters, How to write a custom getter
D
- data classes, A data class lets you create data objects
- about, A data class lets you create data objects, ...that let you destructure data objects, Test drive
- componentN functions and, Data classes define componentN functions...
- constructors with default values, How to use a constructor’s default values
- copying data objects, Copy data objects using the copy function
- creating objects from, A data class lets you create data objects
- defining, A data class lets you create data objects, Generated functions only use properties defined in the constructor
- generated functions and, Generated functions only use properties defined in the constructor
- initializing many properties, Initializing many properties can lead to cumbersome code
- overloading functions, Overloading a function
- overriding inherited behavior, Data classes override their inherited behavior, Test drive
- parameters with default values, Functions can use default values too, Test drive
- primary constructors, Generated functions only use properties defined in the constructor
- rules for, Your Kotlin Toolbox
- secondary constructors, 2. Using named arguments
- data hiding, How to write a custom setter
- data keyword, A data class lets you create data objects
- data objects
- declarations
- abstract classes, Some classes shouldn’t be instantiated
- arrays, var means the variable can point to a different array
- classes, Declare the superclass and its properties and functions as open
- functions, You can get things back from a function
- object, The miracle of object creation, 6. Object declarations and expressions, 7. Extensions
- packages, 1. Packages and imports
- passing values in order of, How to use a constructor’s default values
- properties, How to write a custom getter
- superclasses, Declare the superclass and its properties and functions as open, An overridden function or property stays open...
- variables, Your code needs variables, The miracle of object creation, Lambda expressions have a type
- Decorator pattern, 7. Extensions
- decrement operator (--), How for loops work
- default values
- delay() function, Thread.sleep pauses the current THREAD
- Delegation pattern, 7. Extensions
- derived classes (see subclasses)
- design patterns, 7. Extensions
- destructuring data objects, Data classes define componentN functions...
- do-while loops, Loop and loop and loop...
- dollar sign ($), Add the code to PhraseOMatic.kt
- dot operator (.), We need to convert the value, How to access properties and functions, How to write a custom setter, Which function is called?
- Double type, Integers
- downTo() function, Use downTo to reverse the range
- duplicate code, avoiding, Inheritance helps you avoid duplicate code, Use inheritance to avoid duplicate code in subclasses
- duplicate values
E
- else clause
- Elvis operator (?:), Instead of using an if expression...
- empty constructors, You MUST initialize your properties
- empty function body, The Animal class has two abstract functions
- entries property
- enum classes, 3. Enum classes
- equality operator (==)
- equals operator (=), Loop and loop and loop...
- equals() function
- Exception type, An exception is an object of type Exception
- exceptions
- about, Remove an object reference using null, An exception is thrown in exceptional circumstances, An exception is an object of type Exception, try and throw are both expressions
- catching, An exception is thrown in exceptional circumstances
- ClassCastException, An exception is an object of type Exception
- creating, An exception is an object of type Exception
- defining, An exception is an object of type Exception
- finally block, Catch exceptions using a try/catch
- IllegalArgumentException, An exception is an object of type Exception, You can explicitly throw exceptions
- IllegalStateException, An exception is an object of type Exception
- NullPointerException, Remove an object reference using null, The !! operator deliberately throws a NullPointerException
- rules for, You can explicitly throw exceptions
- throwing, The !! operator deliberately throws a NullPointerException, An exception is thrown in exceptional circumstances, You can explicitly throw exceptions
- try/catch block, Catch exceptions using a try/catch
- explicit casting, Use as to perform an explicit cast, An exception is an object of type Exception
- explicitly declaring variables, How to explicitly declare a variable’s type
- explicitly defining array type, The compiler infers the array’s type from its values
- explicitly throwing exceptions, You can explicitly throw exceptions
- expressions
- Boolean, We need to validate the user’s input
- chaining safe calls together, You can chain safe calls together
- if, Using if to return a value, Add the code to PhraseOMatic.kt, Functions with single-expression bodies, Instead of using an if expression...
- lambda (see lambdas)
- object, Object expressions
- return values and, try and throw are both expressions
- shouldBe, Using KotlinTest
- streamlining with let, Using let with array items
- String templates evaluating, Add the code to PhraseOMatic.kt
- extensions, 7. Extensions
F
- field, backing, How to write a custom setter, How to define interface properties
- file management, You’ve just created your first Kotlin project, Add the main function to App.kt
- filter() function, Kotlin has a bunch of built-in higher-order functions, Meet the filter function
- filterIsInstance() function, Meet the filter function
- filterNot() function, Meet the filter function, The story continues...
- filterTo() function, Meet the filter function, The story continues...
- final keyword, An overridden function or property stays open...
- finally block, Use finally for the things you want to do no matter what, You can explicitly throw exceptions
- Float type, Integers
- fold() function, How to use the fold function, Test drive
- foldRight() function, Test drive
- for loops
- forall() function, Use rows to test against sets of data
- forEach() function, forEach works like a for loop, You can use groupBy in function call chains, Test drive
- forward slash (//), Anatomy of the main function, What can you say in the main function?
- fully qualified names, The fully qualified name
- fun keyword, Anatomy of the main function
- function types, Lambda expressions have a type, What happens when the code runs
- functional programming, Welcome to Kotlinville, Update the Lambdas project
- functions, Define the Contest class
- (see also specific functions)
- about, Let’s build a game: Rock, Paper, Scissors
- abstract, An abstract class can have abstract properties and functions, Let’s define the Roamable interface, Declare that a class implements an interface..., How do you know whether to make a class, a subclass, an abstract class, or an interface?
- accessing for nullable types, How to access a nullable type’s functions and properties
- arguments and, Anatomy of the main function, How you create functions
- calling on object references, Which function is called?
- componentN functions, Data classes define componentN functions...
- concrete, Let’s define the Roamable interface
- conversion, We need to convert the value
- creating, How you create functions
- declaring, You can get things back from a function
- enum classes and, enum properties and functions
- extensions adding, 7. Extensions
- generated, Generated functions only use properties defined in the constructor
- generics and, Things you can do with a generic class or interface, Add the scores property, The compiler can infer the generic type
- higher-order, You can pass a lambda to a function, Update the Lambdas project, infix
- infix, infix
- inheritance and, Inheritance helps you avoid duplicate code, Use inheritance to avoid duplicate code in subclasses, Which function is called?
- interface, Let’s define the Roamable interface, Declare that a class implements an interface..., How do you know whether to make a class, a subclass, an abstract class, or an interface?
- lambdas and, You can pass a lambda to a function, Test drive, A function can return a lambda
- main function, Anatomy of the main function, What can you say in the main function?, Update the main function
- member, Let’s define a Dog class, How to access properties and functions
- object behavior and, We need to convert the value
- of objects, How to design your own classes
- overloading, Test drive, Overloading a function
- overriding (see overriddden functions)
- parameters and, How you create functions, You can use a supertype for a function’s parameters and return type, Test drive, Functions can use default values too, Test drive, Use out to make a generic type covariant
- passing arguments and, How you create functions
- polymorphism and, You can use a supertype for a function’s parameters and return type
- prefixing with final, An overridden function or property stays open...
- prefixing with open, Overriding properties lets you do more than assign default values
- return types and, You can get things back from a function, You can use a supertype for a function’s parameters and return type, Overloading a function, You can use a nullable type everywhere you can use a non-nullable type
- single expression, You can get things back from a function
- String templates calling, Add the code to PhraseOMatic.kt
- suspendable, Thread.sleep pauses the current THREAD
- updating, Java Virtual Machines (JVMs), Loop and loop and loop...
- with default values, Functions can use default values too
- with return values, You can get things back from a function, Code Magnets Solution
- without return values, You can get things back from a function, forEach has no return value
G
- generated functions, properties and, Generated functions only use properties defined in the constructor
- generics and generic types
- about, Collections use generics, Define the Retailer interface, The story continues...
- classes and, Things you can do with a generic class or interface, Test drive, Use out to make a generic type covariant, We need a Vet class, Use in to make a generic type contravariant
- collections and, Collections use generics, Add the scores property
- compiler inferring, Create some Contest objects
- constructors and, Create Vet objects
- contravariant, Use in to make a generic type contravariant, Test drive
- covariant, Use out to make a generic type covariant, Test drive
- functions and, Things you can do with a generic class or interface, Add the scores property, The compiler can infer the generic type
- interfaces and, Things you can do with a generic class or interface, The Retailer hierarchy, Use in to make a generic type contravariant
- invariant, A generic type can be locally contravariant, Test drive
- Java versus Kotlin approach, Test drive
- nullable, Test drive
- objects and, Create some Contest objects, We can create CatRetailer, DogRetailer and FishRetailer objects..., Create Vet objects
- polymorphism and, Things you can do with a generic class or interface, We can create CatRetailer, DogRetailer and FishRetailer objects...
- prefixing with in, Collections use generics, Use in to make a generic type contravariant
- prefixing with out, Collections use generics, Use out to make a generic type covariant, Use in to make a generic type contravariant
- properties and, Add the scores property
- restricting to specific types, Define the Contest class
- subtypes and, Use out to make a generic type covariant, Use in to make a generic type contravariant
- supertypes and, Define the Contest class, Use out to make a generic type covariant, Use in to make a generic type contravariant
- type parameters and, Using type parameters with MutableList
- ways to use, Things you can do with a generic class or interface
- get() function
- getters (accessors), How do you validate property values?, Overriding properties lets you do more than assign default values, You MUST implement all abstract properties and functions, How to define interface properties
- getValue() function (Map), How to use a Map
- GlobalScope.launch, 1. Add a coroutines dependency
- Gradle build tool, Let’s build a drum machine
- greater than operator (>), Loop and loop and loop...
- greater than or equal to operator (>=), Loop and loop and loop...
- groupBy() function, Use groupBy to split your collection into groups
I
- if expression
- if statement
- IllegalArgumentException, An exception is an object of type Exception, You can explicitly throw exceptions
- IllegalStateException, An exception is an object of type Exception
- immutability
- implicit labels, Using labels with return
- import statement, Add the code to the project, The fully qualified name
- in keyword, Collections use generics, Use in to make a generic type contravariant
- in operator, We need to validate the user’s input
- increment operator (++), How for loops work, 8. Return, break and continue
- index (indices), Store multiple values in an array, Your Kotlin Toolbox, Use downTo to reverse the range, List, Set and Map
- indexOf() function (List), Fantastic Lists...
- infix keyword, infix
- inheritance
- about, Inheritance helps you avoid duplicate code
- abstract classes and, How to implement an abstract class
- Any superclass and, equals is inherited from a superclass named Any, A data class lets you create data objects
- avoiding duplicate code with, Inheritance helps you avoid duplicate code, Use inheritance to avoid duplicate code in subclasses
- building class hierarchy, We’ll create some Kotlin animals
- class hierarchy using, Which function is called?
- designing class structure, What we’re going to do
- functions and, Inheritance helps you avoid duplicate code, Use inheritance to avoid duplicate code in subclasses, Which function is called?
- HAS-A test, Use IS-A to test your class hierarchy
- interfaces and, How do you know whether to make a class, a subclass, an abstract class, or an interface?
- IS-A test, Use IS-A to test your class hierarchy, Independent classes can have common behavior, equals is inherited from a superclass named Any
- polymorphism and, You can use a supertype for a function’s parameters and return type
- properties and, Inheritance helps you avoid duplicate code, Use inheritance to avoid duplicate code in subclasses, Inheritance guarantees that all subclasses have the functions and properties defined in the superclass
- subtypes and, Inheritance guarantees that all subclasses have the functions and properties defined in the superclass
- init keyword, How to use initializer blocks
- initialization
- abstract properties and, An abstract class can have abstract properties and functions, How to implement an abstract class
- interface properties and, How to define interface properties
- objects and, How objects are created, How to use initializer blocks
- properties and, How objects are created, Flexible property initialization, You MUST initialize your properties
- property, Initializing many properties can lead to cumbersome code
- superclasses and, How (and when) to override properties
- variables and, How to explicitly declare a variable’s type
- initializer blocks, How to use initializer blocks, How (and when) to override properties
- inline keyword, infix
- inner classes, An inner class can access the outer class members
- installing IntelliJ IDEA IDE, Java Virtual Machines (JVMs), Install IntelliJ IDEA (Community Edition)
- instance variables (see properties)
- instances (see objects)
- instantiation
- Int type, Integers
- IntelliJ IDEA IDE
- interactive shell (see REPL)
- interfaces
- about, An interface lets you define common behavior OUTSIDE a superclass hierarchy
- defining, Let’s define the Roamable interface
- functions in, Let’s define the Roamable interface, Declare that a class implements an interface..., How do you know whether to make a class, a subclass, an abstract class, or an interface?
- generics and, Things you can do with a generic class or interface, The Retailer hierarchy, Use in to make a generic type contravariant
- implementing, How to implement multiple interfaces
- inheritance and, How do you know whether to make a class, a subclass, an abstract class, or an interface?
- instantiation and, An interface lets you define common behavior OUTSIDE a superclass hierarchy
- naming conventions, How do you know whether to make a class, a subclass, an abstract class, or an interface?
- polymorphism and, An interface lets you define common behavior OUTSIDE a superclass hierarchy, Interfaces let you use polymorphism
- properties in, Let’s define the Roamable interface
- tips when creating, How do you know whether to make a class, a subclass, an abstract class, or an interface?
- visibility modifiers and, Visibility modifiers and classes/interfaces
- internal modifier, 2. Visibility modifiers
- interoperability, 10. Interoperability
- invariant generic types, A generic type can be locally contravariant, Test drive
- invoke() function, You can assign a lambda to a variable
- is operator, Interfaces let you use polymorphism, An exception is an object of type Exception
- IS-A test, Use IS-A to test your class hierarchy, Independent classes can have common behavior, equals is inherited from a superclass named Any
- it keyword, Use let to run code if values are not null, The compiler can infer lambda parameter types, Invoke the lambda in the function body, forEach has no return value
- Iterable interface, Test drive
J
- Java libraries, Add the code to the project
- Java programming language, Test drive, 10. Interoperability
- Java Virtual Machines (JVMs), It’s crisp, concise and readable
- JavaScript, It’s crisp, concise and readable, 10. Interoperability
- JUnit library, Kotlin can use existing testing libraries
- JVMs (Java Virtual Machines), It’s crisp, concise and readable
K
- key/value pairs, Time for a Map, You can copy Maps and MutableMaps, Add the scores property
- keys property (Map), You can copy Maps and MutableMaps, Test drive
- Kotlin extension libraries, 7. Extensions
- kotlin package, When in doubt, go to the Library
- Kotlin programming language, Welcome to Kotlinville
- Kotlin Standard Library, When in doubt, go to the Library
- kotlin.collections package, When in doubt, go to the Library
- KotlinTest library, Using KotlinTest
- kt file extension, Add a new Kotlin file to the project
L
- labels/annotations (@), Create a JUnit test class, 8. Return, break and continue
- lambdas
- about, lambdas and higher-order functions: Treating Code Like Data, Test drive
- closure and, forEach has no return value, Test drive
- functional programming and, Update the Lambdas project
- functions and, You can pass a lambda to a function, Test drive, A function can return a lambda
- invoking, You can assign a lambda to a variable
- labeling, Using labels with return
- parameters and, What lambda code looks like, Lambda expressions have a type, You can pass a lambda to a function
- shortcuts for, You can assign a lambda to a variable, What happens when you call the function, Test drive
- variables and, You can assign a lambda to a variable, Lambda expressions have a type, forEach has no return value
- lateinit keyword, You MUST initialize your properties
- launch function, 1. Add a coroutines dependency
- less than operator (<), Loop and loop and loop...
- less than or equal to operator (<=), Loop and loop and loop...
- let keyword, Use let to run code if values are not null, Use the right lambda for the variable’s type
- linking variables to objects (see object references)
- List interface, List, Set and Map, Lists allow duplicate values, Test drive, Meet the filter function, Some more examples of fold, Test drive
- listOf() function (List), Fantastic Lists..., Lists allow duplicate values
- local variables, How you create functions, The story continues
- locally contravariant generic type, A generic type can be locally contravariant
- locally covariant generic type, Test drive
- Long type, Integers
- looping constructs
M
- main function
- Map interface, List, Set and Map, Time for a Map, The sumBy and sumByDouble functions, Meet the filter function, Use groupBy to split your collection into groups, Test drive
- map() function, Use map to apply a transform to your collection
- mapOf() function (Map), Time for a Map
- Math.random() function, Add the code to PhraseOMatic.kt
- max() function, Arrays can be useful..., The min and max functions work with basic types
- maxBy() function, The min and max functions work with basic types
- member functions (methods), Let’s define a Dog class, How to access properties and functions
- min() function, Arrays can be useful..., The min and max functions work with basic types
- minBy() function, The min and max functions work with basic types
- modifiers, visibility, 2. Visibility modifiers
- mutability
- MutableList interface, List, Set and Map, Create a MutableList..., Lists allow duplicate values, How a MutableList is defined, The compiler can infer the generic type
- mutableListOf() function (MutableList), Create a MutableList..., How a MutableList is defined, The compiler can infer the generic type
- MutableMap interface, List, Set and Map, Create a MutableMap, Add the scores property
- mutableMapOf() function (Map), Create a MutableMap
- MutableSet interface, List, Set and Map, How to create a Set, How to use a MutableSet, Create the getWinners function
- mutableSetOf() function (MutableSet), How to use a MutableSet
- mutators (setters), How do you validate property values?, Overriding properties lets you do more than assign default values, You MUST implement all abstract properties and functions, How to define interface properties
N
- named arguments, 2. Using named arguments
- naming conventions for interfaces, How do you know whether to make a class, a subclass, an abstract class, or an interface?
- naming variables, What can you say in the main function?, Your code needs variables, Use the right value for the variable’s type
- native code, It’s crisp, concise and readable, 10. Interoperability
- nested classes, 5. Nested and inner classes
- nextInt() function (Random), Add the code to PhraseOMatic.kt
- not equals operator (!=), Not equals (!= and !), How to access a nullable type’s functions and properties
- not operator (!), Not equals (!= and !), Where to use the is operator
- not-null assertion operator (!!), The !! operator deliberately throws a NullPointerException
- Nothing type, try and throw are both expressions
- null value
- nullable types
- NullPointerException, Remove an object reference using null, The !! operator deliberately throws a NullPointerException, An exception is an object of type Exception
O
- object declarations, The miracle of object creation, 6. Object declarations and expressions, 7. Extensions
- object expressions, Object expressions
- object keyword, 6. Object declarations and expressions
- object references, Store multiple values in an array
- objects
- abstract classes and, Some classes shouldn’t be instantiated
- constructors and, How objects are created
- creating, How to create a Dog object, The miracle of object creation
- creating from data classes, A data class lets you create data objects
- defining types, Object types are defined using classes
- equals function and, == calls a function named equals
- functions of, How to design your own classes
- generics and, Create some Contest objects, We can create CatRetailer, DogRetailer and FishRetailer objects..., Create Vet objects
- initializing, How objects are created, How to use initializer blocks
- properties of (see properties)
- open keyword, Declare the superclass and its properties and functions as open, Overriding properties lets you do more than assign default values, An overridden function or property stays open..., An abstract class can have abstract properties and functions
- opening REPL, Using the Kotlin interactive shell
- or operator (||), We need to validate the user’s input, Where to use the is operator
- out keyword, Collections use generics, Use out to make a generic type covariant, Use in to make a generic type contravariant
- outer classes, 5. Nested and inner classes
- overloading functions, Test drive, Overloading a function
- overridden functions
- data classes and, Data classes override their inherited behavior
- interfaces and, Declare that a class implements an interface...
- open keyword and, Declare the superclass and its properties and functions as open, An overridden function or property stays open...
- overloaded functions versus, Overloading a function
- rules for, How to override functions, Rules for overriding hashCode and equals
- subclasses and, Inheritance helps you avoid duplicate code, What should the subclasses override?, Test drive
- ways to use, How to override functions
- overridden properties
- override keyword, How (and when) to override properties
P
- packages, When in doubt, go to the Library, You can change the order and make bulk changes..., 1. Packages and imports
- parallel execution, Test drive
- parameters
- about, How you create functions
- empty constructors and, You MUST initialize your properties
- functions and, How you create functions, You can use a supertype for a function’s parameters and return type, Test drive, Functions can use default values too, Test drive, Use out to make a generic type covariant
- lambdas and, What lambda code looks like, Lambda expressions have a type, You can pass a lambda to a function
- local variables and, The story continues
- nullable types, You can use a nullable type everywhere you can use a non-nullable type
- order of arguments and, You can send more than one thing to a function
- prefixing with val/var, Going deeper into properties, Your Kotlin Toolbox, Initializing many properties can lead to cumbersome code
- properties as, Going deeper into properties
- separating multiple, You can send more than one thing to a function
- superclass constructors and, How a subclass inherits from a superclass
- type, Using type parameters with MutableList
- variable types matching, You can send more than one thing to a function
- with default values, Functions can use default values too, Test drive
- parentheses ()
- passing values
- platforms
- plus() function (Array), ...but there are things an array can’t handle
- polymorphism
- about, You can use a supertype for a function’s parameters and return type, Test drive, The Animal class has two abstract functions
- abstract functions and, The Animal class has two abstract functions
- abstract properties and, The Animal class has two abstract functions
- Any superclass and, equals is inherited from a superclass named Any
- generics and, Things you can do with a generic class or interface, We can create CatRetailer, DogRetailer and FishRetailer objects...
- independent classes and, Independent classes can have common behavior
- interfaces and, An interface lets you define common behavior OUTSIDE a superclass hierarchy, Interfaces let you use polymorphism
- primary constructors
- print command, A loopy example
- println command
- printStackTrace() function, An exception is an object of type Exception
- private modifier, 2. Visibility modifiers
- projects
- properties, We need to convert the value
- about, We need to convert the value, How to design your own classes, Behind the scenes: calling the Dog constructor
- abstract, An abstract class can have abstract properties and functions, Declare that a class implements an interface...
- accessing, How to access properties and functions
- as parameters, Going deeper into properties
- assigning default values to, Initializing many properties can lead to cumbersome code
- constructors defining, Behind the scenes: calling the Dog constructor, Behind the scenes: calling the Dog constructor, Generated functions only use properties defined in the constructor
- data hiding values, How to write a custom setter
- data objects and, Data classes override their inherited behavior
- declaring, How to write a custom getter
- defining in main body of class, Flexible property initialization
- enum classes and, enum properties and functions
- extensions adding, 7. Extensions
- flexible initialization, Flexible property initialization
- generated functions and, Generated functions only use properties defined in the constructor
- generics and, Add the scores property
- inheritance and, Inheritance helps you avoid duplicate code, Use inheritance to avoid duplicate code in subclasses, Inheritance guarantees that all subclasses have the functions and properties defined in the superclass
- initializing, How objects are created, Flexible property initialization, You MUST initialize your properties, Initializing many properties can lead to cumbersome code
- interface, Let’s define the Roamable interface
- nullable types, You can use a nullable type everywhere you can use a non-nullable type, How to access a nullable type’s functions and properties
- overriding (see overridden properties)
- prefixing with final, An overridden function or property stays open...
- prefixing with open, Overriding properties lets you do more than assign default values
- String templates referencing, Add the code to PhraseOMatic.kt
- validating values, How do you validate property values?
- protected modifier, Visibility modifiers and classes/interfaces
- public modifier, 2. Visibility modifiers
- put() function (Map), Create a MutableMap
- putAll() function (Map), Create a MutableMap
R
- random number generation, Add the code to PhraseOMatic.kt
- Random.nextInt() function, Add the code to PhraseOMatic.kt
- range of numbers
- range operator (..), How for loops work
- reading user input, Ask the user for their choice
- readLine() function, Ask the user for their choice, We need to validate the user’s input
- reduce() function, Test drive
- reduceRight() function, Test drive
- referential equality operator (===), ...that let you destructure data objects, How a Set checks for duplicates
- remove() function
- removeAll() function
- removeAt() function (MutableList), You can remove a value...
- REPL (interactive shell), Install IntelliJ IDEA (Community Edition)
- retainAll() function
- return statement, 8. Return, break and continue
- return type
- return values
- expressions and, Using if to return a value, Use when to compare a variable against a bunch of options, try and throw are both expressions
- functions with, You can get things back from a function, Code Magnets Solution
- functions without, You can get things back from a function, forEach has no return value
- interface properties and, How to define interface properties
- lambdas and, Lambda expressions have a type
- null value, Ask the user for their choice, We need to validate the user’s input
- reverse() function
- reversed() function, You can change the order and make bulk changes...
- Rock, Paper, Scissors game
- row() function, Use rows to test against sets of data
- rules
- Run command, Test drive
- runBlocking() function, Use runBlocking to run coroutines in the same scope
S
- safe call operator (?.), Keep things safe with safe calls, Use let to run code if values are not null
- safe calls
- safe explicit casts, An exception is an object of type Exception
- sealed classes, 4. Sealed classes
- secondary constructors, 2. Using named arguments, Test drive
- Set interface, List, Set and Map, How to create a Set, Test drive, Test drive, Test drive
- set() function (MutableList), You can remove a value...
- setOf() function (Set), How to create a Set
- setters (mutators), How do you validate property values?, Overriding properties lets you do more than assign default values, You MUST implement all abstract properties and functions, How to define interface properties
- Short type, Integers
- short-circuiting, We need to validate the user’s input
- shouldBe expression, Using KotlinTest
- shuffle() function (MutableList), You can change the order and make bulk changes...
- shuffled() function (MutableList), You can change the order and make bulk changes...
- single expression functions, Functions with single-expression bodies
- Singleton pattern, 7. Extensions
- size property
- sleep() function, Thread.sleep pauses the current THREAD
- smart casts, The is operator usually performs a smart cast, An exception is an object of type Exception
- sort() function
- sortBy() function (MutableList), Introducing lambdas
- sorted() function (MutableList), You can change the order and make bulk changes...
- spread operator (*), 9. More fun with functions
- src folder
- state (objects), We need to convert the value, Design an animal class inheritance structure
- statements
- storing values in arrays, Store multiple values in an array
- String templates, Add the code to PhraseOMatic.kt
- string type, Anatomy of the main function, Booleans
- subclasses
- about, Inheritance helps you avoid duplicate code
- adding constructors to, How a subclass inherits from a superclass
- defining, How a subclass inherits from a superclass
- functions and, Inheritance helps you avoid duplicate code, Use inheritance to avoid duplicate code in subclasses, How to override functions, Which function is called?
- inheritance (see inheritance)
- initializer blocks in, How (and when) to override properties
- polymorphism and, You can use a supertype for a function’s parameters and return type, The Animal class has two abstract functions
- properties and, Inheritance helps you avoid duplicate code, Use inheritance to avoid duplicate code in subclasses, Overriding properties lets you do more than assign default values, Inheritance guarantees that all subclasses have the functions and properties defined in the superclass
- tips when creating, How do you know whether to make a class, a subclass, an abstract class, or an interface?
- subtypes
- sum() function (Array), Arrays can be useful...
- sumBy() function, The sumBy and sumByDouble functions
- sumByDouble() function, The sumBy and sumByDouble functions
- superclasses, Inheritance helps you avoid duplicate code
- about, Inheritance helps you avoid duplicate code
- abstract, Some classes shouldn’t be instantiated, How to implement an abstract class
- declaring, Declare the superclass and its properties and functions as open, An overridden function or property stays open...
- functions and, Inheritance helps you avoid duplicate code, Use inheritance to avoid duplicate code in subclasses, How to override functions, Which function is called?
- inheritance (see inheritance)
- polymorphism and, The Animal class has two abstract functions
- primary constructors, How a subclass inherits from a superclass, Declare that a class implements an interface...
- properties and, Inheritance helps you avoid duplicate code, Use inheritance to avoid duplicate code in subclasses, How (and when) to override properties, An overridden function or property stays open..., Inheritance guarantees that all subclasses have the functions and properties defined in the superclass
- supertypes, Define the Contest class
- suspendable functions, Thread.sleep pauses the current THREAD
T
- templates
- test-intro, Who should probably back away from this book?
- tests and testing
- threads, Test drive
- throw keyword, You can explicitly throw exceptions
- throwing exceptions, The !! operator deliberately throws a NullPointerException, An exception is thrown in exceptional circumstances, You can explicitly throw exceptions
- toByte() function, We need to convert the value
- toDouble() function, We need to convert the value
- toFloat() function, We need to convert the value
- toInt() function, We need to convert the value, Add the code to PhraseOMatic.kt
- toList() function
- toLong() function, We need to convert the value
- toLowerCase() function, Add the printResult function to Game.kt
- toMap() function (MutableMap), You can copy Maps and MutableMaps
- toMutableList() function
- toMutableMap() function (MutableMap), You can copy Maps and MutableMaps
- toMutableSet() function (Array), Test drive
- Tools menu (IntelliJ IDEA), Using the Kotlin interactive shell
- toSet() function
- toShort() function, We need to convert the value
- toString() function, The common behavior defined by Any, A data class lets you create data objects, Test drive
- toTypedArray() function
- toUpperCase() function, Add the printResult function to Game.kt, Flexible property initialization
- try block (try/catch), How to override functions, Catch exceptions using a try/catch, You can explicitly throw exceptions
- two’s complement, Watch out for overspill
- type parameters, Using type parameters with MutableList
- typealias keyword, Use typealias to provide a different name for an existing type
- types
- converting values of, We need to convert the value
- function, Lambda expressions have a type, What happens when the code runs
- generic (see generics and generic types)
- inferring for arrays, The compiler infers the array’s type from its values
- nullable, How to create an array of nullable types, Use let to run code if values are not null, ...but there are things an array can’t handle, Test drive
- of collections, List, Set and Map, Lists allow duplicate values, Test drive
- return, You can get things back from a function, You can use a supertype for a function’s parameters and return type, Overloading a function, You can use a nullable type everywhere you can use a non-nullable type, Use in to make a generic type contravariant
- subtypes (see subtypes)
- supertypes (see supertypes)
- variable, Your code needs variables
V
- val keyword
- about, What can you say in the main function?, Test drive
- assigning lambdas to variables, You can assign a lambda to a variable
- declaring arrays using, val means the variable points to the same array forever...
- defining properties and, Behind the scenes: calling the Dog constructor
- getters and setters, How to write a custom setter
- overriding properties and, Overriding properties lets you do more than assign default values, Test drive
- parameter variables and, The story continues
- prefixing parameters with, Going deeper into properties, Your Kotlin Toolbox, Initializing many properties can lead to cumbersome code
- var versus, What can you say in the main function?, The variable holds a reference to the object, Behind the scenes: calling the Dog constructor
- validating
- values
- assigning, Your code needs variables, How to explicitly declare a variable’s type
- assigning to safe calls, You can use safe calls to assign values...
- converting, We need to convert the value
- data hiding property, How to write a custom setter
- duplicate, List, Set and Map, Lists allow duplicate values, How a Set checks for duplicates, You can copy a MutableSet
- enum classes, 3. Enum classes
- inferring array type from, The compiler infers the array’s type from its values
- initializing for variables, How to explicitly declare a variable’s type
- object state and, How to create a Dog object, Design an animal class inheritance structure
- return, Using if to return a value, You can get things back from a function
- reusability of, What can you say in the main function?, Your code needs variables, The variable holds a reference to the object, var means the variable can point to a different array
- storing in arrays, Store multiple values in an array
- validating property, How do you validate property values?
- values property (Map), You can copy Maps and MutableMaps, Test drive
- var keyword
- about, What can you say in the main function?, Test drive
- assigning lambdas to variables, You can assign a lambda to a variable
- declaring arrays using, var means the variable can point to a different array
- defining properties and, Behind the scenes: calling the Dog constructor
- getters and setters, How to write a custom setter
- lateinit keyword and, You MUST initialize your properties
- overriding properties and, Overriding properties lets you do more than assign default values, Test drive
- prefixing parameters with, Going deeper into properties, Your Kotlin Toolbox, Initializing many properties can lead to cumbersome code
- smart casting and, The is operator usually performs a smart cast
- updating properties and, How to access properties and functions
- val versus, What can you say in the main function?, The variable holds a reference to the object, Behind the scenes: calling the Dog constructor
- vararg keyword, 9. More fun with functions
- variables
- about, Your code needs variables, The variable holds a reference to the object
- assigning values, Your code needs variables, How to explicitly declare a variable’s type
- Boolean tests on, Loop and loop and loop...
- comparing options for, Use when to compare a variable against a bunch of options
- converting values, We need to convert the value
- creating, Your code needs variables
- declaring, Your code needs variables, The miracle of object creation, Lambda expressions have a type
- initializing, How to explicitly declare a variable’s type
- instance, Behind the scenes: calling the Dog constructor
- lambdas and, You can assign a lambda to a variable, Lambda expressions have a type, forEach has no return value
- local, How you create functions, The story continues
- matching parameter type, You can send more than one thing to a function
- naming, What can you say in the main function?, Your code needs variables, Use the right value for the variable’s type
- object references and (see object references)
- prefixing with $, Add the code to PhraseOMatic.kt
- reusability of, What can you say in the main function?, Your code needs variables, The variable holds a reference to the object, var means the variable can point to a different array
- types of, Your code needs variables
- version control, IntelliJ IDEA and, Install IntelliJ IDEA (Community Edition)
- visibility modifiers, 2. Visibility modifiers
..................Content has been hidden....................
You can't read the all page of ebook, please click
here login for view all page.