SlideShare ist ein Scribd-Unternehmen logo
1 von 109
Downloaden Sie, um offline zu lesen
• 

• 4 

• 

•
Kotlin Night
Effective Kotlin
Effective Java?🤔
Kotlin Java ?
( )

Kotlin , 

.
, 

.

- Andrey
Q. Kotlin .
.
.
- Andrey
Q. JVM 

?
, , . 

.
- Hadi hariri
Q. ?
Kotlin ,
.
Kotlin
Effective Kotlin
Effective Java?🤔
Effective Java
3rd Edition
Java 



• 

• 

•
1.  

2.  

3. private  

4. private  

5.  

6. 

…. 
Kotlin 

!
Effective Java 

?
• Effecive Java Kotlin


• Effective Kotlin !
Effecive Java Kotlin
Item 3
public class NutritionFacts {
private final int servingSize; !// (mL, 1 )
private final int servings; !// ( , n )
private final int calories; !// (1 )
private final int fat; !// (g/1 )
private final int sodium; !// (mg/1 )
private final int carbohydrate; !// (g/1 )
}
public NutritionFacts(int servingSize, int servings) {
this(servingSize, servings, 0);
}
public NutritionFacts(int servingSize, int servings,
int calories) {
this(servingSize, servings, calories, 0);
}
public NutritionFacts(int servingSize, int servings,
int calories, int fat,
int sodium, int carbohydrate) {
this.servingSize = servingSize;
this.servings = servings;
this.calories = calories;
this.fat = fat;
this.sodium = sodium;
this.carbohydrate = carbohydrate;
}
public static void main(String[] args) {
NutritionFacts cocaCola =
new NutritionFacts(240, 8, 100, 0, 35, 27);
}
• 

•
public static void main(String[] args) {
NutritionFacts cocaCola = new NutritionFacts();
cocaCola.setServingSize(240);
cocaCola.setServings(8);
cocaCola.setCalories(100);
cocaCola.setSodium(35);
cocaCola.setCarbohydrate(27);
}
• 

•
public class NutritionFacts {
public static class Builder {
!//
}
public static void main(String[] args) {
NutritionFacts cocaCola = new NutritionFacts
.Builder(240, 8)
.calories(100)
.sodium(35)
.carbohydrate(27)
.build();
}
}
public static class Builder {
!//
private final int servingSize;
private final int servings;
!// - .
private int calories = 0;
private int fat = 0;
private int sodium = 0;
private int carbohydrate = 0;
public Builder(int servingSize, int servings) {
this.servingSize = servingSize;
this.servings = servings;
}
public Builder calories(int val) {
calories = val;
return this;
}
!//
}
Boilerplate 😵
class NutritionFacts(
private val servingSize: Int,
private val servings: Int,
private val calories: Int = 0,
private val fat: Int = 0,
private val sodium: Int = 0,
private val carbohydrate: Int = 0
)
Default arguments
val nutritionFacts = NutritionFacts(
servingSize = 240,
servings = 8,
calories = 100,
fat = 0,
sodium = 35,
carbohydrate = 27
)
Named arguments 

Named arguments 

Default arguments
Item 3
private 

Item 3
• 

• 

.
public class Elvis {
public static final Elvis INSTANCE = new Elvis();
private Elvis() { }
public void leaveTheBuilding() {
System.out.println("Whoa baby, I'm outta here!");
}
public static void main(String[] args) {
Elvis elvis = Elvis.INSTANCE;
elvis.leaveTheBuilding();
}
}
object Elvis {
fun leaveTheBuilding() {
println("Whoa baby, I'm outta here!");
}
}
fun main() {
Elvis.leaveTheBuilding()
}
Decompile ?
public final class Elvis {
public static final Elvis INSTANCE;
public final void leaveTheBuilding() {
String var1 = "Whoa baby, I'm outta here!";
System.out.println(var1);
}
private Elvis() {
}
static {
Elvis var0 = new Elvis();
INSTANCE = var0;
}
}
object Elvis {
fun leaveTheBuilding() {
println("Whoa baby, I'm outta here!");
}
}
fun main() {
Elvis.leaveTheBuilding()
}
object 

Item 3
private
private
Item 4
class NoConstructor private constructor()
val noConstructor = NoConstructor()
Compile Error!
?
.

( )
class NoConstructor private constructor() {
val number = 1
fun printHello() {
println("Hello!")
}
}
val number = 1
fun printHello() {
println("Hello!")
}
,
Top Level function
Item 4


private
Item 18
• - , 



• 

• InstrumentedHashSet 

• HashSet
class InstrumentedHashSet<E> : HashSet<E> {
var addCount = 0
private set
override fun add(element: E): Boolean {
addCount!++
return super.add(element)
}
override fun addAll(elements: Collection<E>): Boolean {
addCount += elements.size
return super.addAll(elements)
}
}
fun main() {
val s = InstrumentedHashSet<String>()
s.addAll(List.of("1", "2", “3"))
println(s.addCount)
}
“6” 🤔
3 “3”
public boolean addAll(Collection<? extends E> c) {
boolean modified = false;
for (E e : c)
if (add(e))
modified = true;
return modified;
}
HashSet AbstractSet
override fun add(element: E): Boolean {
addCount!++
return super.add(element)
}
override fun addAll(elements: Collection<E>): Boolean {
addCount += elements.size
return super.addAll(elements)
}
addAll elements ,

super.addAll add
open class ForwardingSet<E>(
private val s: MutableSet<E>
) : MutableSet<E> {
override fun add(element: E): Boolean {
return s.add(element)
}
override fun addAll(elements: Collection<E>): Boolean {
return s.addAll(elements)
}
clear, iterator, remove, removeAll, ………
}
class InstrumentedHashSet<E> : ForwardingSet<E>(HashSet()) {
!//
var addCount = 0
private set
override fun add(element: E): Boolean {
addCount!++
return super.add(element)
}
override fun addAll(elements: Collection<E>): Boolean {
addCount += elements.size
return super.addAll(elements)
}
} “3” !
override fun add(element: E): Boolean {
addCount!++
return super.add(element)
}
override fun addAll(elements: Collection<E>): Boolean {
addCount += elements.size
return super.addAll(elements)
}
super.addAll, ForwardingSet addAll 

InstrumentedHashSet add .
•   .
.

•
.
.
.
open class ForwardingSet<E>(
private val s: MutableSet<E>
) : MutableSet<E> {
override fun add(element: E): Boolean {
return s.add(element)
}
override fun addAll(elements: Collection<E>): Boolean {
return s.addAll(elements)
}
clear, iterator, remove, removeAll, ………
}
open class ForwardingSet<E>(
private val s: MutableSet<E>
) : MutableSet<E> by s
class InstrumentedHashSet<E>(
private val s: MutableSet<E>
) : MutableSet<E> by s {
var addCount = 0
private set
override fun add(element: E): Boolean {
addCount!++
return s.add(element)
}
override fun addAll(elements: Collection<E>): Boolean {
addCount += elements.size
return s.addAll(elements)
}
}
.

Kotlin (Deleagte ) 

by .
Item 18
. 

Item 19
•
, 

•
.

•
.
class Parent { }
class Child extends Parent { }
final class Parent { }
class Child extends Parent { }
class Parent
class Child : Parent()
open class Parent
class Child : Parent()
. 

.
Item 19
.
public public
Item 16
Public
public class Point {
public double x;
public double y;
}
public class Point {
private double x;
private double y;
public double getX() { return x; }
public double getY() { return y; }
public void setX(double x) { this.x = x; }
public void setY(double y) { this.y = y; }
}
Public
public class Point {
public double x;
public double y;
}
• API 

.

• .

• .

• .
class Point {
var x : Double = 0.0
var y : Double = 0.0
}
class Point {
var x : Double = 0.0
get() {
println("x ")
return field
}
var y : Double = 0.0
get() {
println("y ")
return field
}
}
Kotlin Getter, Setter 



.
Item 16
public public
@Override 

Item 40
public class Monogram {
private final char character;
public Monogram(char character) {
this.character = character;
}
public boolean equals(Monogram m) {
return character !== m.character;
}
public static void main(String[] args) {
Set<Monogram> set = new HashSet<Monogram>();
set.add(new Monogram('a'));
set.add(new Monogram('a'));
System.out.println(set.size());
}
1 “2”
equals ,

!
@Override ?
public class Monogram {
private final char character;
public Monogram(char character) {
this.character = character;
}
@Override
public boolean equals(Monogram m) {
return character !== m.character;
}
public static void main(String[] args) {
Set<Monogram> set = new HashSet<Monogram>();
set.add(new Monogram('a'));
set.add(new Monogram('a'));
System.out.println(set.size());
}
}
Compile error
Object 

!🧐
public class Monogram {
@Override
public boolean equals(Object o) {
if (!(o instanceof Monogram)) return false;
Monogram monogram = (Monogram) o;
return character !== monogram.character;
}
public static void main(String[] args) {
Set<Monogram> set = new HashSet<Monogram>();
set.add(new Monogram('a'));
set.add(new Monogram('a'));
System.out.println(set.size());
}
} “1”
class Monogram(private val character: Char) {
override fun equals(other: Any?): Boolean {
return if(other is Monogram) {
character !== other.character
} else {
false
}
}
}
Compile error
Java @Override 

. 

Kotlin 

override .
Item 40
@Override
Item 17
( )
• 

• .

•
.

• ( )

• 

•
• Java

private char character = 'a';
private final char character = 'a';
• Kotlin

private var character: Char = 'a'
private val character: Char = ‘a'
final VS val ?
• final - , 

• val, var - 

• ( ) ,


• , val
Kotlin List vs Java List(Kotlin MuableList)
• Kotlin List (add, addAll)
- Read Only 

• Mutable , List
List
.
.

Kotlin .
Item 17
Item 61
• 

• int, double, boolean 

• 

• String, List 

• .

• - Integer, Double, Boolean
vs
•
. 

• null .

•
.
Kotlin ?
• Kotlin .(int, boolean)

• ,
(Nullable, Generics ) 

.
private static final int a = 3;
@Nullable
private static final Integer b = 3;
val a: Int = 3
val b: Int? = 3
Decompile
Kotlin ,
.
Item 61
equals 

equals hashCode 

toString
Item 10, 11, 12
Java Object equals, Kotlin Any equals
• (reflexivity) : null x , x.equals(x) true .

• (symmertry): null x, y , x.equals(y) true
y.equals(x) true .

• (transitivity): null x, y, z x.equals(y) true
, y.equals(z) true x.equals(z) true .

• (consistency): null x, y , x.equals(y)
true false .

• null- : null x , x.equals(null) false .
Java Object equals, Kotlin Any equals
• (reflexivity) : null x , x.equals(x) true .

• (symmertry): null x, y , x.equals(y) true
y.equals(x) true .

• (transitivity): null x, y, z x.equals(y) true
, y.equals(z) true x.equals(z) true .

• (consistency): null x, y , x.equals(y)
true false .

• null- : null x , x.equals(null) false .
data class MyData(val text: String)
Java Hashcode
• equals ,
hashCode
. , .

• equals(Object) , hashCode
.

• equals(Object) , hashCode
.
.
HashCode (?)
• int result c . c 2.a .
equals . 10 ).

• f .

• c .

• , Type.hashCode(f) . Type .

• equals equals , hashCode
. , (canonical representation)
hashCode . null 0 ( 0 .)

• , .
, 2.b . (0 ) .
Arrays.hashCode .

• 2.a c result . .

result = 31 * result + c;

• result .
HashCode (?)
• int result c . c 2.a .
equals . 10 ).

• f .

• c .

• , Type.hashCode(f) . Type .

• equals equals , hashCode
. , (canonical representation)
hashCode . null 0 ( 0 .)

• , .
, 2.b . (0 ) .
Arrays.hashCode .

• 2.a c result . .

result = 31 * result + c;

• result .
data class MyData(val text: String)
toString
• toString
. 

• toString
.
data class Student(
val name: String,
val score: Int
)
fun main() {
val student = Student(" ", 42)
println(student)
}
Student(name= , score=42)
Data class equals, hashCode,
toString .
Item 10, 11, 12
equals 

equals hashCode 

toString
Item 77
try {
!//
} catch (Exception e) {
e.printStackTrace();
}
?
try {
!//
} catch (Exception e) {
e.printStackTrace();
}
• 

•


• 



?🤔
Checked Exception
• try - catch , throw Exception 

Appendable append(CharSequence csq) throws IOException;
• 

• 

• 

•
Kotlin ?
• Checked Exception 

• - ,
“ ”
try {
!//
} catch (Exception e) {
e.printStackTrace();
}
“ ” 

UncheckedException
Kotlin CheckedException .

.
Item 77
Item 83
• 

• .

• , 

• Kotlin Delegated Properties(by lazy)
val number by lazy {
expensiveFunction()
}
fun <T> lazy(
mode: LazyThreadSafetyMode,
initializer: () !-> T
)
public enum class LazyThreadSafetyMode {
SYNCHRONIZED,
PUBLICATION,
NONE,
}
val number by lazy(LazyThreadSafetyMode.NONE) {
expensiveFunction()
}
Kotlin Deleagted Properties(by lazy)

.

.
Item 83
API
Item 31
List<? extends Number> numbers;
if(condition) {
numbers = new ArrayList<Int>();
} else {
numbers = new ArrayList<Double>();
}
val numbers: List<Number> = if(condition) {
ArrayList<Int>()
} else {
ArrayList<Double>()
}
Declaration-site variance,

Use-site variance 

API
Item 31


API
!🥳

Weitere ähnliche Inhalte

Was ist angesagt?

[수정본] 우아한 객체지향
[수정본] 우아한 객체지향[수정본] 우아한 객체지향
[수정본] 우아한 객체지향Young-Ho Cho
 
The aggregate function - from sequential and parallel folds to parallel aggre...
The aggregate function - from sequential and parallel folds to parallel aggre...The aggregate function - from sequential and parallel folds to parallel aggre...
The aggregate function - from sequential and parallel folds to parallel aggre...Philip Schwarz
 
카카오톡의 서버사이드 코틀린
카카오톡의 서버사이드 코틀린카카오톡의 서버사이드 코틀린
카카오톡의 서버사이드 코틀린if kakao
 
[OKKYCON] 정진욱 - 테스트하기 쉬운 코드로 개발하기
[OKKYCON] 정진욱 - 테스트하기 쉬운 코드로 개발하기[OKKYCON] 정진욱 - 테스트하기 쉬운 코드로 개발하기
[OKKYCON] 정진욱 - 테스트하기 쉬운 코드로 개발하기OKKY
 
Kotlin Coroutines. Flow is coming
Kotlin Coroutines. Flow is comingKotlin Coroutines. Flow is coming
Kotlin Coroutines. Flow is comingKirill Rozov
 
炎炎夏日學 Android 課程 - Part1: Kotlin 語法介紹
炎炎夏日學 Android 課程 -  Part1: Kotlin 語法介紹炎炎夏日學 Android 課程 -  Part1: Kotlin 語法介紹
炎炎夏日學 Android 課程 - Part1: Kotlin 語法介紹Johnny Sung
 
Izumi 1.0: Your Next Scala Stack
Izumi 1.0: Your Next Scala StackIzumi 1.0: Your Next Scala Stack
Izumi 1.0: Your Next Scala Stack7mind
 
Functional Programming 101 with Scala and ZIO @FunctionalWorld
Functional Programming 101 with Scala and ZIO @FunctionalWorldFunctional Programming 101 with Scala and ZIO @FunctionalWorld
Functional Programming 101 with Scala and ZIO @FunctionalWorldJorge Vásquez
 
Spring Framework Petclinic sample application
Spring Framework Petclinic sample applicationSpring Framework Petclinic sample application
Spring Framework Petclinic sample applicationAntoine Rey
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event LoopDesignveloper
 
Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017Roman Elizarov
 
R で解く FizzBuzz 問題
R で解く FizzBuzz 問題R で解く FizzBuzz 問題
R で解く FizzBuzz 問題Kosei ABE
 
Why The Free Monad isn't Free
Why The Free Monad isn't FreeWhy The Free Monad isn't Free
Why The Free Monad isn't FreeKelley Robinson
 
우아한 모노리스
우아한 모노리스우아한 모노리스
우아한 모노리스Arawn Park
 
The effective use of Django ORM
The effective use of Django ORMThe effective use of Django ORM
The effective use of Django ORMYaroslav Muravskyi
 
스프링5 웹플럭스와 테스트 전략
스프링5 웹플럭스와 테스트 전략스프링5 웹플럭스와 테스트 전략
스프링5 웹플럭스와 테스트 전략if kakao
 
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PGPgDay.Seoul
 

Was ist angesagt? (20)

[수정본] 우아한 객체지향
[수정본] 우아한 객체지향[수정본] 우아한 객체지향
[수정본] 우아한 객체지향
 
The aggregate function - from sequential and parallel folds to parallel aggre...
The aggregate function - from sequential and parallel folds to parallel aggre...The aggregate function - from sequential and parallel folds to parallel aggre...
The aggregate function - from sequential and parallel folds to parallel aggre...
 
카카오톡의 서버사이드 코틀린
카카오톡의 서버사이드 코틀린카카오톡의 서버사이드 코틀린
카카오톡의 서버사이드 코틀린
 
Introduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTXIntroduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTX
 
[OKKYCON] 정진욱 - 테스트하기 쉬운 코드로 개발하기
[OKKYCON] 정진욱 - 테스트하기 쉬운 코드로 개발하기[OKKYCON] 정진욱 - 테스트하기 쉬운 코드로 개발하기
[OKKYCON] 정진욱 - 테스트하기 쉬운 코드로 개발하기
 
Kotlin Coroutines. Flow is coming
Kotlin Coroutines. Flow is comingKotlin Coroutines. Flow is coming
Kotlin Coroutines. Flow is coming
 
炎炎夏日學 Android 課程 - Part1: Kotlin 語法介紹
炎炎夏日學 Android 課程 -  Part1: Kotlin 語法介紹炎炎夏日學 Android 課程 -  Part1: Kotlin 語法介紹
炎炎夏日學 Android 課程 - Part1: Kotlin 語法介紹
 
Izumi 1.0: Your Next Scala Stack
Izumi 1.0: Your Next Scala StackIzumi 1.0: Your Next Scala Stack
Izumi 1.0: Your Next Scala Stack
 
Functional Programming 101 with Scala and ZIO @FunctionalWorld
Functional Programming 101 with Scala and ZIO @FunctionalWorldFunctional Programming 101 with Scala and ZIO @FunctionalWorld
Functional Programming 101 with Scala and ZIO @FunctionalWorld
 
Spring Framework Petclinic sample application
Spring Framework Petclinic sample applicationSpring Framework Petclinic sample application
Spring Framework Petclinic sample application
 
SWTBot Tutorial
SWTBot TutorialSWTBot Tutorial
SWTBot Tutorial
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
 
Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017
 
R で解く FizzBuzz 問題
R で解く FizzBuzz 問題R で解く FizzBuzz 問題
R で解く FizzBuzz 問題
 
Why The Free Monad isn't Free
Why The Free Monad isn't FreeWhy The Free Monad isn't Free
Why The Free Monad isn't Free
 
우아한 모노리스
우아한 모노리스우아한 모노리스
우아한 모노리스
 
Beyond Scala Lens
Beyond Scala LensBeyond Scala Lens
Beyond Scala Lens
 
The effective use of Django ORM
The effective use of Django ORMThe effective use of Django ORM
The effective use of Django ORM
 
스프링5 웹플럭스와 테스트 전략
스프링5 웹플럭스와 테스트 전략스프링5 웹플럭스와 테스트 전략
스프링5 웹플럭스와 테스트 전략
 
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
 

Ähnlich wie Effective Java and Kotlin

Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Mohamed Nabil, MSc.
 
Kotlin for backend development (Hackaburg 2018 Regensburg)
Kotlin for backend development (Hackaburg 2018 Regensburg)Kotlin for backend development (Hackaburg 2018 Regensburg)
Kotlin for backend development (Hackaburg 2018 Regensburg)Tobias Schneck
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kirill Rozov
 
Feel of Kotlin (Berlin JUG 16 Apr 2015)
Feel of Kotlin (Berlin JUG 16 Apr 2015)Feel of Kotlin (Berlin JUG 16 Apr 2015)
Feel of Kotlin (Berlin JUG 16 Apr 2015)intelliyole
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Cody Engel
 
Functional programming basics
Functional programming basicsFunctional programming basics
Functional programming basicsopenbala
 
TDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
TDC218SP | Trilha Kotlin - DSLs in a Kotlin WayTDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
TDC218SP | Trilha Kotlin - DSLs in a Kotlin Waytdc-globalcode
 
First few months with Kotlin - Introduction through android examples
First few months with Kotlin - Introduction through android examplesFirst few months with Kotlin - Introduction through android examples
First few months with Kotlin - Introduction through android examplesNebojša Vukšić
 
Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)Gesh Markov
 
Introduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxIntroduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxDavid Rodenas
 
Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with AndroidKurt Renzo Acosta
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)Eduard Tomàs
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016Codemotion
 

Ähnlich wie Effective Java and Kotlin (20)

Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
 
Kotlin on android
Kotlin on androidKotlin on android
Kotlin on android
 
Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Kotlin for backend development (Hackaburg 2018 Regensburg)
Kotlin for backend development (Hackaburg 2018 Regensburg)Kotlin for backend development (Hackaburg 2018 Regensburg)
Kotlin for backend development (Hackaburg 2018 Regensburg)
 
Kotlin decompiled
Kotlin decompiledKotlin decompiled
Kotlin decompiled
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
 
Feel of Kotlin (Berlin JUG 16 Apr 2015)
Feel of Kotlin (Berlin JUG 16 Apr 2015)Feel of Kotlin (Berlin JUG 16 Apr 2015)
Feel of Kotlin (Berlin JUG 16 Apr 2015)
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
 
Functional programming basics
Functional programming basicsFunctional programming basics
Functional programming basics
 
TDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
TDC218SP | Trilha Kotlin - DSLs in a Kotlin WayTDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
TDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
 
Kotlin Generation
Kotlin GenerationKotlin Generation
Kotlin Generation
 
First few months with Kotlin - Introduction through android examples
First few months with Kotlin - Introduction through android examplesFirst few months with Kotlin - Introduction through android examples
First few months with Kotlin - Introduction through android examples
 
Kotlin intro
Kotlin introKotlin intro
Kotlin intro
 
Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)
 
Introduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxIntroduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicox
 
Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with Android
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 

Kürzlich hochgeladen

VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 

Kürzlich hochgeladen (20)

VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 

Effective Java and Kotlin

  • 1.
  • 2. • • 4 • •
  • 6. ( ) Kotlin , 
 . , 
 . - Andrey Q. Kotlin .
  • 8. , , . 
 . - Hadi hariri Q. ?
  • 11. Effective Java 3rd Edition Java 
 
 • • •
  • 12. 1.   2.   3. private   4. private   5.   6. …. 
  • 14. • Effecive Java Kotlin • Effective Kotlin ! Effecive Java Kotlin
  • 16. public class NutritionFacts { private final int servingSize; !// (mL, 1 ) private final int servings; !// ( , n ) private final int calories; !// (1 ) private final int fat; !// (g/1 ) private final int sodium; !// (mg/1 ) private final int carbohydrate; !// (g/1 ) }
  • 17. public NutritionFacts(int servingSize, int servings) { this(servingSize, servings, 0); } public NutritionFacts(int servingSize, int servings, int calories) { this(servingSize, servings, calories, 0); } public NutritionFacts(int servingSize, int servings, int calories, int fat, int sodium, int carbohydrate) { this.servingSize = servingSize; this.servings = servings; this.calories = calories; this.fat = fat; this.sodium = sodium; this.carbohydrate = carbohydrate; }
  • 18. public static void main(String[] args) { NutritionFacts cocaCola = new NutritionFacts(240, 8, 100, 0, 35, 27); } • •
  • 19. public static void main(String[] args) { NutritionFacts cocaCola = new NutritionFacts(); cocaCola.setServingSize(240); cocaCola.setServings(8); cocaCola.setCalories(100); cocaCola.setSodium(35); cocaCola.setCarbohydrate(27); } • •
  • 20. public class NutritionFacts { public static class Builder { !// } public static void main(String[] args) { NutritionFacts cocaCola = new NutritionFacts .Builder(240, 8) .calories(100) .sodium(35) .carbohydrate(27) .build(); } }
  • 21. public static class Builder { !// private final int servingSize; private final int servings; !// - . private int calories = 0; private int fat = 0; private int sodium = 0; private int carbohydrate = 0; public Builder(int servingSize, int servings) { this.servingSize = servingSize; this.servings = servings; } public Builder calories(int val) { calories = val; return this; } !// } Boilerplate 😵
  • 22. class NutritionFacts( private val servingSize: Int, private val servings: Int, private val calories: Int = 0, private val fat: Int = 0, private val sodium: Int = 0, private val carbohydrate: Int = 0 ) Default arguments
  • 23. val nutritionFacts = NutritionFacts( servingSize = 240, servings = 8, calories = 100, fat = 0, sodium = 35, carbohydrate = 27 ) Named arguments 

  • 24. Named arguments Default arguments Item 3
  • 27. public class Elvis { public static final Elvis INSTANCE = new Elvis(); private Elvis() { } public void leaveTheBuilding() { System.out.println("Whoa baby, I'm outta here!"); } public static void main(String[] args) { Elvis elvis = Elvis.INSTANCE; elvis.leaveTheBuilding(); } }
  • 28. object Elvis { fun leaveTheBuilding() { println("Whoa baby, I'm outta here!"); } } fun main() { Elvis.leaveTheBuilding() }
  • 29. Decompile ? public final class Elvis { public static final Elvis INSTANCE; public final void leaveTheBuilding() { String var1 = "Whoa baby, I'm outta here!"; System.out.println(var1); } private Elvis() { } static { Elvis var0 = new Elvis(); INSTANCE = var0; } } object Elvis { fun leaveTheBuilding() { println("Whoa baby, I'm outta here!"); } } fun main() { Elvis.leaveTheBuilding() }
  • 32. class NoConstructor private constructor() val noConstructor = NoConstructor() Compile Error!
  • 34. class NoConstructor private constructor() { val number = 1 fun printHello() { println("Hello!") } }
  • 35. val number = 1 fun printHello() { println("Hello!") }
  • 38. • - , 
 • • InstrumentedHashSet • HashSet
  • 39. class InstrumentedHashSet<E> : HashSet<E> { var addCount = 0 private set override fun add(element: E): Boolean { addCount!++ return super.add(element) } override fun addAll(elements: Collection<E>): Boolean { addCount += elements.size return super.addAll(elements) } }
  • 40. fun main() { val s = InstrumentedHashSet<String>() s.addAll(List.of("1", "2", “3")) println(s.addCount) } “6” 🤔 3 “3”
  • 41. public boolean addAll(Collection<? extends E> c) { boolean modified = false; for (E e : c) if (add(e)) modified = true; return modified; } HashSet AbstractSet
  • 42. override fun add(element: E): Boolean { addCount!++ return super.add(element) } override fun addAll(elements: Collection<E>): Boolean { addCount += elements.size return super.addAll(elements) } addAll elements , super.addAll add
  • 43. open class ForwardingSet<E>( private val s: MutableSet<E> ) : MutableSet<E> { override fun add(element: E): Boolean { return s.add(element) } override fun addAll(elements: Collection<E>): Boolean { return s.addAll(elements) } clear, iterator, remove, removeAll, ……… }
  • 44. class InstrumentedHashSet<E> : ForwardingSet<E>(HashSet()) { !// var addCount = 0 private set override fun add(element: E): Boolean { addCount!++ return super.add(element) } override fun addAll(elements: Collection<E>): Boolean { addCount += elements.size return super.addAll(elements) } } “3” !
  • 45. override fun add(element: E): Boolean { addCount!++ return super.add(element) } override fun addAll(elements: Collection<E>): Boolean { addCount += elements.size return super.addAll(elements) } super.addAll, ForwardingSet addAll 
 InstrumentedHashSet add .
  • 47. open class ForwardingSet<E>( private val s: MutableSet<E> ) : MutableSet<E> { override fun add(element: E): Boolean { return s.add(element) } override fun addAll(elements: Collection<E>): Boolean { return s.addAll(elements) } clear, iterator, remove, removeAll, ……… }
  • 48. open class ForwardingSet<E>( private val s: MutableSet<E> ) : MutableSet<E> by s
  • 49. class InstrumentedHashSet<E>( private val s: MutableSet<E> ) : MutableSet<E> by s { var addCount = 0 private set override fun add(element: E): Boolean { addCount!++ return s.add(element) } override fun addAll(elements: Collection<E>): Boolean { addCount += elements.size return s.addAll(elements) } }
  • 50. .
 Kotlin (Deleagte ) by . Item 18
  • 53. class Parent { } class Child extends Parent { }
  • 54. final class Parent { } class Child extends Parent { }
  • 56. open class Parent class Child : Parent()
  • 57.
  • 60. Public public class Point { public double x; public double y; }
  • 61. public class Point { private double x; private double y; public double getX() { return x; } public double getY() { return y; } public void setX(double x) { this.x = x; } public void setY(double y) { this.y = y; } }
  • 62. Public public class Point { public double x; public double y; } • API 
 . • . • . • .
  • 63. class Point { var x : Double = 0.0 var y : Double = 0.0 }
  • 64. class Point { var x : Double = 0.0 get() { println("x ") return field } var y : Double = 0.0 get() { println("y ") return field } }
  • 65. Kotlin Getter, Setter 
 
 . Item 16 public public
  • 67. public class Monogram { private final char character; public Monogram(char character) { this.character = character; } public boolean equals(Monogram m) { return character !== m.character; } public static void main(String[] args) { Set<Monogram> set = new HashSet<Monogram>(); set.add(new Monogram('a')); set.add(new Monogram('a')); System.out.println(set.size()); } 1 “2” equals ,
 ! @Override ?
  • 68. public class Monogram { private final char character; public Monogram(char character) { this.character = character; } @Override public boolean equals(Monogram m) { return character !== m.character; } public static void main(String[] args) { Set<Monogram> set = new HashSet<Monogram>(); set.add(new Monogram('a')); set.add(new Monogram('a')); System.out.println(set.size()); } } Compile error Object !🧐
  • 69. public class Monogram { @Override public boolean equals(Object o) { if (!(o instanceof Monogram)) return false; Monogram monogram = (Monogram) o; return character !== monogram.character; } public static void main(String[] args) { Set<Monogram> set = new HashSet<Monogram>(); set.add(new Monogram('a')); set.add(new Monogram('a')); System.out.println(set.size()); } } “1”
  • 70. class Monogram(private val character: Char) { override fun equals(other: Any?): Boolean { return if(other is Monogram) { character !== other.character } else { false } } } Compile error
  • 71. Java @Override 
 . 
 Kotlin 
 override . Item 40 @Override
  • 73. ( ) • • . • . • ( ) • •
  • 74. • Java private char character = 'a'; private final char character = 'a'; • Kotlin private var character: Char = 'a' private val character: Char = ‘a'
  • 75. final VS val ? • final - , • val, var - • ( ) , • , val
  • 76. Kotlin List vs Java List(Kotlin MuableList) • Kotlin List (add, addAll) - Read Only • Mutable , List List .
  • 79. • • int, double, boolean • • String, List • . • - Integer, Double, Boolean
  • 80. vs • . • null . • .
  • 81. Kotlin ? • Kotlin .(int, boolean) • , (Nullable, Generics ) 
 .
  • 82. private static final int a = 3; @Nullable private static final Integer b = 3; val a: Int = 3 val b: Int? = 3 Decompile
  • 84. equals equals hashCode toString Item 10, 11, 12
  • 85. Java Object equals, Kotlin Any equals • (reflexivity) : null x , x.equals(x) true . • (symmertry): null x, y , x.equals(y) true y.equals(x) true . • (transitivity): null x, y, z x.equals(y) true , y.equals(z) true x.equals(z) true . • (consistency): null x, y , x.equals(y) true false . • null- : null x , x.equals(null) false .
  • 86. Java Object equals, Kotlin Any equals • (reflexivity) : null x , x.equals(x) true . • (symmertry): null x, y , x.equals(y) true y.equals(x) true . • (transitivity): null x, y, z x.equals(y) true , y.equals(z) true x.equals(z) true . • (consistency): null x, y , x.equals(y) true false . • null- : null x , x.equals(null) false . data class MyData(val text: String)
  • 87. Java Hashcode • equals , hashCode . , . • equals(Object) , hashCode . • equals(Object) , hashCode . .
  • 88. HashCode (?) • int result c . c 2.a . equals . 10 ). • f . • c . • , Type.hashCode(f) . Type . • equals equals , hashCode . , (canonical representation) hashCode . null 0 ( 0 .) • , . , 2.b . (0 ) . Arrays.hashCode . • 2.a c result . .
 result = 31 * result + c; • result .
  • 89. HashCode (?) • int result c . c 2.a . equals . 10 ). • f . • c . • , Type.hashCode(f) . Type . • equals equals , hashCode . , (canonical representation) hashCode . null 0 ( 0 .) • , . , 2.b . (0 ) . Arrays.hashCode . • 2.a c result . .
 result = 31 * result + c; • result . data class MyData(val text: String)
  • 91. data class Student( val name: String, val score: Int ) fun main() { val student = Student(" ", 42) println(student) } Student(name= , score=42)
  • 92. Data class equals, hashCode, toString . Item 10, 11, 12 equals equals hashCode toString
  • 94. try { !// } catch (Exception e) { e.printStackTrace(); }
  • 95. ? try { !// } catch (Exception e) { e.printStackTrace(); } • • • 
 
 ?🤔
  • 96. Checked Exception • try - catch , throw Exception Appendable append(CharSequence csq) throws IOException; • • • •
  • 97. Kotlin ? • Checked Exception • - , “ ”
  • 98. try { !// } catch (Exception e) { e.printStackTrace(); } “ ” UncheckedException
  • 101. • • . • , • Kotlin Delegated Properties(by lazy)
  • 102. val number by lazy { expensiveFunction() }
  • 103. fun <T> lazy( mode: LazyThreadSafetyMode, initializer: () !-> T ) public enum class LazyThreadSafetyMode { SYNCHRONIZED, PUBLICATION, NONE, }
  • 104. val number by lazy(LazyThreadSafetyMode.NONE) { expensiveFunction() }
  • 105. Kotlin Deleagted Properties(by lazy) . . Item 83
  • 107. List<? extends Number> numbers; if(condition) { numbers = new ArrayList<Int>(); } else { numbers = new ArrayList<Double>(); } val numbers: List<Number> = if(condition) { ArrayList<Int>() } else { ArrayList<Double>() }
  • 109. !🥳