Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Data classes in Kotlin
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Harri Kirik
April 02, 2018
Programming
45
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Data classes in Kotlin
5-minute talk about data classes in Kotlin
Harri Kirik
April 02, 2018
More Decks by Harri Kirik
See All by Harri Kirik
Secure programming techniques: Mobile Development Security guest lecture
harri35
0
92
Support for HSM-like capabilities in Android
harri35
0
170
Why doesn't my in-app QR code work (on location)?
harri35
0
55
Git merge-base
harri35
1
90
Smoke testing your library
harri35
0
39
Collections in Kotlin
harri35
0
43
How to do delegation in Kotlin
harri35
0
46
Two-factor authentication at GDG Riga
harri35
0
86
Two-factor authentication at GDG Tartu
harri35
0
67
Other Decks in Programming
See All in Programming
最近”作らせてる” ローカルAIアプリの話
akit37
0
470
外から家のPCの電源入れたい!をPHPで解決する
kawashimo0
1
130
TechTown - Creating Composable Callables in Contemporary C++
rollbear
0
130
Simple Storage Service(S3) is not simple
iwatsukayura
0
290
JIS keyboard support in Omarchy
lef237
0
110
カツオ、ご期待ください
suneo3476
0
190
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
880
残高管理から台帳サービスへの進化
artoy
1
200
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5.2k
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
270
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
590
Featured
See All Featured
The browser strikes back
jonoalderson
0
1.8k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.7k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
360
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
620
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
890
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
630
Prompt Engineering for Job Search
mfonobong
0
520
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
600
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
460
Transcript
designing & developing for mobile Demoday, 02/04/2018 Harri Kirik, engineer
Kotlin: Data classes
Kotlin KOTLIN: DATA CLASSES #kotlin
Classes to hold data KOTLIN: DATA CLASSES #dataclasses
Usually in Java .. KOTLIN: DATA CLASSES #kotlin
KOTLIN: DATA CLASSES public class Person { private String customerEmail;
private String customerPhoneNr; private String customerSurname; private String customerSurnameReading; private String customerGivenName; private String customerGivenNameReading; private String customerCompany; private String customerCompanyDepartment; public Person() { } public void setCustomerEmail(String customerEmail) { this.customerEmail = customerEmail; } public void setCustomerPhoneNr(String customerPhoneNr) { this.customerPhoneNr = customerPhoneNr; } #demoday
KOTLIN: DATA CLASSES public void setCustomerSurname(String customerSurname) { this.customerSurname =
customerSurname; } public void setCustomerSurnameReading(String customerSurnameReading) { this.customerSurnameReading = customerSurnameReading; } public void setCustomerGivenName(String customerGivenName) { this.customerGivenName = customerGivenName; } public void setCustomerGivenNameReading(String customerGivenNameReading) { this.customerGivenNameReading = customerGivenNameReading; } public void setCustomerCompany(String customerCompany) { this.customerCompany = customerCompany; } public void setCustomerCompanyDepartment(String customerCompanyDepartment) { this.customerCompanyDepartment = customerCompanyDepartment; } #demoday
KOTLIN: DATA CLASSES @Override public boolean equals(Object o) { if
(this == o) return true; if (o == null || getClass() != o.getClass()) return false; Person person = (Person) o; if (customerEmail != null ? !customerEmail.equals(person.customerEmail) : person.customerEmail != null) return false; if (customerPhoneNr != null ? !customerPhoneNr.equals(person.customerPhoneNr) : person.customerPhoneNr != null) return false; if (customerSurname != null ? !customerSurname.equals(person.customerSurname) : person.customerSurname != null) return false; if (customerSurnameReading != null ? !customerSurnameReading.equals(person.customerSurnameReading) : person.customerSurnameReading != null) return false; if (customerGivenName != null ? !customerGivenName.equals(person.customerGivenName) : person.customerGivenName != null) return false; if (customerGivenNameReading != null ? !customerGivenNameReading.equals(person.customerGivenNameReading) : person.customerGivenNameReading != null) return false; if (customerCompany != null ? !customerCompany.equals(person.customerCompany) : person.customerCompany != null) return false; return customerCompanyDepartment != null ? customerCompanyDepartment.equals(person.customerCompanyDepartment) : person.customerCompanyDepartment == null; } #demoday
KOTLIN: DATA CLASSES @Override public int hashCode() { int result
= customerEmail != null ? customerEmail.hashCode() : 0; result = 31 * result + (customerPhoneNr != null ? customerPhoneNr.hashCode() : 0); result = 31 * result + (customerSurname != null ? customerSurname.hashCode() : 0); result = 31 * result + (customerSurnameReading != null ? customerSurnameReading.hashCode() : 0); result = 31 * result + (customerGivenName != null ? customerGivenName.hashCode() : 0); result = 31 * result + (customerGivenNameReading != null ? customerGivenNameReading.hashCode() : 0); result = 31 * result + (customerCompany != null ? customerCompany.hashCode() : 0); result = 31 * result + (customerCompanyDepartment != null ? customerCompanyDepartment.hashCode() : 0); return result; } #demoday
KOTLIN: DATA CLASSES @Override public String toString() { return "Person{"
+ "customerEmail='" + customerEmail + '\'' + ", customerPhoneNr='" + customerPhoneNr + '\'' + ", customerSurname='" + customerSurname + '\'' + ", customerSurnameReading='" + customerSurnameReading + '\'' + ", customerGivenName='" + customerGivenName + '\'' + ", customerGivenNameReading='" + customerGivenNameReading + '\'' + ", customerCompany='" + customerCompany + '\'' + ", customerCompanyDepartment='" + customerCompanyDepartment + '\'' + '}'; } } #demoday
Easy to generate, but tedious KOTLIN: DATA CLASSES #dataclasses
Kotlin can do better KOTLIN: DATA CLASSES #dataclasses
KOTLIN: DATA CLASSES data class Person(val customerEmail: String, val customerPhoneNr:
String, val customerSurname: String, val customerSurnameReading: String, val customerGivenName: String, val customerGivenNameReading: String, val customerCompany: String, val customerCompanyDepartment: String) #demoday
Autogenerated: 1. equals()/hashCode() pair; 2. toString() 3. componentN() functions 4.
copy() function KOTLIN: DATA CLASSES #dataclasses
conponentN() functions KOTLIN: DATA CLASSES #dataclasses
KOTLIN: DATA CLASSES val person = Person( "
[email protected]
", // <-
getComponent1() "+37256240131", //<- getComponent2() "Kirik", //<- getComponent3() "Kirik", //<- getComponent4() "Harri", //<- getComponent5() "Harri", //<- getComponent6() "Mobi Lab", //<- getComponent7() "Development"); //<- getComponent1() val (_, _,surname, _, givenName) = person // (C1), (C2), C3, C4 #demoday
copy() function KOTLIN: DATA CLASSES #dataclasses
KOTLIN: DATA CLASSES val person = Person("
[email protected]
", "+37256240131", "Kirik", "Kirik",
"Harri", "Harri", "Mobi Lab", "Development"); val personFired = person.copy( customerEmail = "
[email protected]
", customerCompany = "N/A", customerCompanyDepartment = "N/A") #demoday
http:// lab.mobi designing & developing for mobile thanks Questions?