Жанры
Авторы
Контакты
О сайте
Книжные новинки
Популярные книги
Найти
Главная
Авторы
Бретт Мак-Лахлин
Programming Kotlin Applications
Читать книгу Programming Kotlin Applications - Бретт Мак-Лахлин, Brett McLaughlin - Страница 1
Оглавление
Предыдущая
Следующая
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
90
Оглавление
Купить и скачать книгу
Вернуться на страницу книги Programming Kotlin Applications
Оглавление
Страница 1
Table of Contents
List of Tables
List of Illustrations
Guide
Pages
Programming Kotlin
®
Applications BUILDING MOBILE AND SERVER-SIDE APPLICATIONS WITH KOTLIN
Страница 8
Страница 9
ABOUT THE AUTHOR
ABOUT THE TECHNICAL EDITOR
ACKNOWLEDGMENTS
Страница 13
1 Objects All the Way Down WHAT'S IN THIS CHAPTER?
KOTLIN: A NEW PROGRAMMING LANGUAGE
LISTING 1.1
: A simple Kotlin program using classes and lists
WHAT IS KOTLIN?
What Does Kotlin Add to Java?
KOTLIN IS OBJECT-ORIENTED
LISTING 1.2
: A very useless object in Kotlin (and a main function to use it)
INTERLUDE: SET UP YOUR KOTLIN ENVIRONMENT
Install Kotlin (and an IDE)
Install IntelliJ
Create Your Kotlin Program
Compile and Run Your Kotlin Program
Fix Any Errors as They Appear
Install Kotlin (and Use the Command Line)
Command-Line Kotlin on Windows
Command-Line Kotlin on Mac OS X
Command-Line Kotlin on UNIX-Based Systems
Verify Your Command-Line Installation
CREATING USEFUL OBJECTS
Pass In Values to an Object Using Its Constructor
LISTING 1.3
: A less useless object in Kotlin and its constructor
LISTING 1.4
: Cutting out the constructor keyword
Print an Object with toString()
Terminology Update: Functions and Methods
Print an Object (and Do It with Shorthand)
Override the toString() Method
All Data Is Not a Property Value
LISTING 1.5
: Converting data to actual properties
INITIALIZE AN OBJECT AND CHANGE A VARIABLE
LISTING 1.6
: Creating a new property for a Person
Initialize a Class with a Block
Kotlin Auto-Generates Getters and Setters
Terminology Update: Getters, Setters, Mutators, Accessors
Constants Can't Change (Sort of)
LISTING 1.7
Using mutable variables
2 It's Hard to Break Kotlin WHAT'S IN THIS CHAPTER?
UPGRADE YOUR KOTLIN CLASS GAME
Name a File According to Its Class
LISTING 2.1
: The Person code from Chapter 1
LISTING 2.2
: Main function for testing the Person class
Organize Your Classes with Packages
Put Person in a Package
Classes: The Ultimate Type in Kotlin
KOTLIN HAS A LARGE NUMBER OF TYPES
Numbers in Kotlin
Letters and Things
Truth or Fiction
Types Aren't Interchangeable (Part 1)
LISTING 2.3
: Person with extra properties
You Must Initialize Your Properties
Types Aren't Interchangeable (Part 2)
LISTING 2.4
: Filling out your Person instances
You Can Explicitly Tell Kotlin What Type to Use
Try to Anticipate How Types Will Be Used
It's Easy to Break Kotlin (Sort of)
OVERRIDING PROPERTY ACCESSORS AND MUTATORS
Custom-Set Properties Can't Be in a Primary Constructor
Move Properties Out of Your Primary Constructors
Initialize Properties Immediately
LISTING 2.5
: Assigning constructor information to properties
Try to Avoid Overusing Names
LISTING 2.6
: Clarifying property names and constructor inputs
Override Mutators for Certain Properties
LISTING 2.7
: Defining custom mutators for lastName and firstName
CLASSES CAN HAVE CUSTOM BEHAVIOR
Define a Custom Method on Your Class
LISTING 2.8
: Creating a new property method to update the fullName variable
Every Property Must Be Initialized
Assign an Uninitialized Property a Dummy Value
Tell Kotlin You'll Initialize a Property Later
Assign Your Property the Return Value from a Function
Listing 2.9
Getting the fullName property correct (partially)
Sometimes You Don't Need a Property!
LISTING 2.10
: A much simpler version of Person
TYPE SAFETY CHANGES EVERYTHING
WRITING CODE IS RARELY LINEAR
{buyButton}
Подняться наверх