SlideShare ist ein Scribd-Unternehmen logo
1 von 37
Downloaden Sie, um offline zu lesen
KOTLIN初體驗
andyang@AndroidTaipei
@2017 PKLOT CO., LTD
@2017 PKLOT CO., LTD
ABOUT ME
▸ Andy
▸ @ 停⾞車車⼤大聲公
▸ @ Android Developer 讀書會 (TADSG)
▸ @ Android Code Club (週三晚上)
@2017 PKLOT CO., LTD
有⼈人聽過 KOTLIN 嗎?
@2017 PKLOT CO., LTD
有⼈人⽤用過 KOTLIN 嗎?
@2017 PKLOT CO., LTD
HELLO KOTLIN
▸ JetBrains 開發的 JVM 語⾔言
▸ 包含很多 Effective Java 的思想在裡⾯面
▸ Java 開發者的夢幻語⾔言 ?!
@2017 PKLOT CO., LTD
WHY KOTLIN
▸ Short Code
▸ Null Safety
▸ Smart Cast
▸ Lambda (Functional Programing)
▸ Method Extension
▸ Hybrid with Java
▸ Default final
▸ Everything is Object
@2017 PKLOT CO., LTD
HOW KOTLIN
▸ Install Android Studio Plugin “Kotlin”
▸ cmd + shift + a -> Configure kotlin in Project
▸ classpth : “org.jetbrains.kotlin:lotlin-gradle-plugin:1.0.7”
▸ apply plugin: ‘kotlin-android’
▸ compile ‘org.jetbrains.kotlin:kotlin-stdlib:1.0.7’
@2017 PKLOT CO., LTD
JAVA TO KOTLIN
▸ 遇到不知道如何表達的 kotlin 語法可以先透過轉換觀察
▸ cmd + shift + a -> Convert Java File to Kotlin
▸ ⼀一鍵完成
@2017 PKLOT CO., LTD
KOTLIN FEATURE
▸ Multiple class in one file
▸ Data Class
▸ Properties val/var
▸ Null Safety
▸ Smart Cast
▸ Method Extension / infix
▸ Lambda
▸ Operator Overloading
▸ Companion object
▸ Delegate
▸ Dependency Injection
@2017 PKLOT CO., LTD
MULTIPLE CLASS IN ONE FILE
▸ Class 的整理理更更有彈性
▸ 同質性⾼高且簡易易的 Class 可以放到⼀一起
▸ 提⾼高閱讀,不易易中斷思考
@2017 PKLOT CO., LTD
DATA CLASS
▸ hashCode()
▸ toString()
▸ equals()
▸ with properties
@2017 PKLOT CO., LTD
PROPERTIES
▸ var(variable)
▸ var age (compile error)
▸ var age:Int (compile error)
▸ var age = 1 (ok)
▸ age = 2 (ok)
▸ age = null (ok)
▸ var myAge = age (ok)
@2017 PKLOT CO., LTD
PROPERTIES
▸ val(value)
▸ val age (compile error)
▸ val age:Int (compile error)
▸ val age = 18 (ok)
▸ age = 19 (compile error)
@2017 PKLOT CO., LTD
NULL SAFETY
▸ NullPointerException
▸ ? -> nullable, default non null
▸ var order : Order? = Order()
▸ order?.price (null safety if order is null)
▸ order.price (compile error)
@2017 PKLOT CO., LTD
SMART CASE
▸ ClassCastException
▸ Stupid Case
if(exception instanceOf HttpException) {
HttpException httpException = (HttpException) exception
int code = httpException.getStatusCode();
}
@2017 PKLOT CO., LTD
SMART CASE
▸ Smart Case
when(exception) {
is HttpException -> {
int code = exception.statusCode
}
default -> {
// do something else
}
}
@2017 PKLOT CO., LTD
METHOD EXTENSION / INFIX
▸ Method Extension
var name : String = null
val isNull = name.isNullOrEmpty()
▸ In Java
if(name == null || name.length == 0)
StringUtils.isNullOrEmpty(name)
@2017 PKLOT CO., LTD
METHOD EXTENSION / INFIX
▸ How
fun CharSequence?.isNullOrEmpty() : Boolean
= this == null || this.lenght == 0
@2017 PKLOT CO., LTD
METHOD EXTENSION / INFIX
▸ Infix
▸ val isLike = “ABC” like “123-ABC”
infix fun String.like(it: String) : Boolean =
this.toUpperCase.contains(it)
▸ “name” to “Andy”
mapOf(
Pair(“nickName”, “andyang”),
“name” to “Andy”
)
@2017 PKLOT CO., LTD
LAMBDA
▸ 不必再等 Java 8 到天荒地老
▸ 不⽤用 Retrolambda
▸ Kotlin 內建 lambda
@2017 PKLOT CO., LTD
LAMBDA
▸ setOnClickListener()
view.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
Toast.makeToast(…..).show()
}
})
@2017 PKLOT CO., LTD
LAMBDA
▸ setOnClickListener()
view.setOnClickListener({ view ->
Toast.makeToast(…..).show()
})
view.setOnClickListener({
Toast.makeToast(…..).show()
})
@2017 PKLOT CO., LTD
LAMBDA
▸ setOnClickListener()
view.setOnClickListener{ Toast.makeToast(…..).show()}
view.onClick{ Toast.makeToast(…..).show()}
@2017 PKLOT CO., LTD
LAMBDA
▸ Adapter OnItemClickListener
interface OnOrderItemClickListener{
onOrderItemClick(Order order);
}
OnOrderItemClickListener onOrderItemClickListener;
‣ interface, setter, init, invoke
@2017 PKLOT CO., LTD
LAMBDA
▸ Adapter OnItemClickListener in Kotlin
var onOrderItemClickListener : (order: Order) -> Unit
holder?.onClick{
onOrderItemClickListener.invoke(order)
}
holder?.onClick{
onOrderItemClickListener(order)
}
@2017 PKLOT CO., LTD
OPERATOR OVERLOADING
▸ a == b -> a.equals(b)
▸ a + b -> a.plus(b)
▸ a - b, a * b, a / b, a % b …..
▸ a..b -> a.rangeTo(b)
▸ a in b -> a.contains(b)
▸ a[i] -> a.get(i)
▸ a[i] = b -> a.set(i, b)
@2017 PKLOT CO., LTD
COMPANION OBJECT
class App : Application() {
companion object {
private var instance: Application? = null
fun instance() = instance
}
override fun onCreate() {
super.onCreate();
instance = this
}
}
@2017 PKLOT CO., LTD
PROPERTISE DELEGATE
class Delegate<T> : ReadWriteProperty<Any?, T> {
override fun getValue(thisRef: Any?, property : KPropety<*>) {
}
override fun setValue(thisRef: Any?, property : KPropety<*>, value: T) {
}
}
var name : String by Delegate()
@2017 PKLOT CO., LTD
PROPERTISE DELEGATE
‣ Demo Delegate SharedPreferences
@2017 PKLOT CO., LTD
DEPENDENCY INJECTION
‣ In MPV Pattern
‣ Presenter need inject Model
‣ Repository(NetworkService networkService, LocalData localData)
‣ LocalData(Content context)
‣ Presenter(View view, Repository repository)
@2017 PKLOT CO., LTD
DEPENDENCY INJECTION
‣ new Presenter
‣ In Java
Presenter presenter = new Presenter(new Repository(new
NetworkService(), new LocalData(context))); // so ugly
Presenter presenter = PresenterFactory.create();
@2017 PKLOT CO., LTD
DEPENDENCY INJECTION
‣ In kotlin
‣ Repository(networkService : NetworkService = NetworkService(),
localData : LocalData = LocalData())
‣ LocalData(context : Content = App.instance())
‣ Presenter(view : View, repository : Repository = Repository())
@2017 PKLOT CO., LTD
DEPENDENCY INJECTION
‣ In kotlin
‣ val presenter = Presenter(view)
‣ for testing
‣ val presenter = Presenter(view, mockRepository)
@2017 PKLOT CO., LTD
REFERENCE
▸ Kotlin official guide
▸ https://kotlinlang.org/docs/reference/
▸ Kotlin For Android Developer (e-book)
▸ https://antonioleiva.com/kotlin-android-developers-book/
@2017 PKLOT CO., LTD
學習⼀一⾨門語⾔言最快的⽅方式就是只能⽤用它!
@2017 PKLOT CO., LTD
Q&A
@2017 PKLOT CO., LTD
停車大聲公
總是給你更好的停車體驗

Weitere ähnliche Inhalte

Was ist angesagt?

Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐KAI CHU CHUNG
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Rajmahendra Hegde
 
#MBLTdev: Разработка первоклассных SDK для Android (Twitter)
#MBLTdev: Разработка первоклассных SDK для Android (Twitter)#MBLTdev: Разработка первоклассных SDK для Android (Twitter)
#MBLTdev: Разработка первоклассных SDK для Android (Twitter)e-Legion
 
Using Monitoring & Configuration Management to restart services.
Using Monitoring & Configuration Management to restart services.Using Monitoring & Configuration Management to restart services.
Using Monitoring & Configuration Management to restart services.gregretkowski
 
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...ZeroTurnaround
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new buildIgor Khotin
 
Build microservice with gRPC in golang
Build microservice with gRPC in golangBuild microservice with gRPC in golang
Build microservice with gRPC in golangTing-Li Chou
 
Using the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentUsing the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentSchalk Cronjé
 
用 Go 語言打造多台機器 Scale 架構
用 Go 語言打造多台機器 Scale 架構用 Go 語言打造多台機器 Scale 架構
用 Go 語言打造多台機器 Scale 架構Bo-Yi Wu
 
Gdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpackGdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpackKAI CHU CHUNG
 
Reactive Programming by UniRx for Asynchronous & Event Processing
Reactive Programming by UniRx for Asynchronous & Event ProcessingReactive Programming by UniRx for Asynchronous & Event Processing
Reactive Programming by UniRx for Asynchronous & Event ProcessingYoshifumi Kawai
 

Was ist angesagt? (11)

Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
 
#MBLTdev: Разработка первоклассных SDK для Android (Twitter)
#MBLTdev: Разработка первоклассных SDK для Android (Twitter)#MBLTdev: Разработка первоклассных SDK для Android (Twitter)
#MBLTdev: Разработка первоклассных SDK для Android (Twitter)
 
Using Monitoring & Configuration Management to restart services.
Using Monitoring & Configuration Management to restart services.Using Monitoring & Configuration Management to restart services.
Using Monitoring & Configuration Management to restart services.
 
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new build
 
Build microservice with gRPC in golang
Build microservice with gRPC in golangBuild microservice with gRPC in golang
Build microservice with gRPC in golang
 
Using the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentUsing the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM Development
 
用 Go 語言打造多台機器 Scale 架構
用 Go 語言打造多台機器 Scale 架構用 Go 語言打造多台機器 Scale 架構
用 Go 語言打造多台機器 Scale 架構
 
Gdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpackGdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpack
 
Reactive Programming by UniRx for Asynchronous & Event Processing
Reactive Programming by UniRx for Asynchronous & Event ProcessingReactive Programming by UniRx for Asynchronous & Event Processing
Reactive Programming by UniRx for Asynchronous & Event Processing
 

Ähnlich wie Kotlin初體驗

Kotlin 初體驗
Kotlin 初體驗Kotlin 初體驗
Kotlin 初體驗哲偉 楊
 
Summer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampSummer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampKai Koenig
 
黑豹 ch4 ddd pattern pracrice
黑豹 ch4 ddd pattern pracrice黑豹 ch4 ddd pattern pracrice
黑豹 ch4 ddd pattern pracriceFong Liou
 
Android 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutesAndroid 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutesKai Koenig
 
Creative Solutions to Already Solved Problems II
Creative Solutions to Already Solved Problems IICreative Solutions to Already Solved Problems II
Creative Solutions to Already Solved Problems IIGene Gotimer
 
Is writing performant code too expensive?
Is writing performant code too expensive? Is writing performant code too expensive?
Is writing performant code too expensive? Tomasz Kowalczewski
 
GDG Kuwait - Modern android development
GDG Kuwait - Modern android developmentGDG Kuwait - Modern android development
GDG Kuwait - Modern android developmentGDGKuwaitGoogleDevel
 
2017: Kotlin - now more than ever
2017: Kotlin - now more than ever2017: Kotlin - now more than ever
2017: Kotlin - now more than everKai Koenig
 
Grails EE
Grails EEGrails EE
Grails EEGR8Conf
 
GR8Conf 2011: GContracts
GR8Conf 2011: GContractsGR8Conf 2011: GContracts
GR8Conf 2011: GContractsGR8Conf
 
Effective codereview | Dave Liddament | CODEiD
Effective codereview | Dave Liddament | CODEiDEffective codereview | Dave Liddament | CODEiD
Effective codereview | Dave Liddament | CODEiDCODEiD PHP Community
 
Is writing performant code too expensive?
Is writing performant code too expensive? Is writing performant code too expensive?
Is writing performant code too expensive? Tomasz Kowalczewski
 
Little Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinLittle Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinKai Koenig
 
Anko - The Ultimate Ninja of Kotlin Libraries?
Anko - The Ultimate Ninja of Kotlin Libraries?Anko - The Ultimate Ninja of Kotlin Libraries?
Anko - The Ultimate Ninja of Kotlin Libraries?Kai Koenig
 
Practices For Becoming A Better Programmer
Practices For Becoming A Better ProgrammerPractices For Becoming A Better Programmer
Practices For Becoming A Better ProgrammerSrikanth Shreenivas
 
The road to continuous deployment (DomCode September 2016)
The road to continuous deployment (DomCode September 2016)The road to continuous deployment (DomCode September 2016)
The road to continuous deployment (DomCode September 2016)Michiel Rook
 
Coding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinCoding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinKai Koenig
 

Ähnlich wie Kotlin初體驗 (20)

Kotlin 初體驗
Kotlin 初體驗Kotlin 初體驗
Kotlin 初體驗
 
Summer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampSummer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcamp
 
黑豹 ch4 ddd pattern pracrice
黑豹 ch4 ddd pattern pracrice黑豹 ch4 ddd pattern pracrice
黑豹 ch4 ddd pattern pracrice
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScript
 
Android 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutesAndroid 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutes
 
Smoke testing with Go
Smoke testing with GoSmoke testing with Go
Smoke testing with Go
 
Creative Solutions to Already Solved Problems II
Creative Solutions to Already Solved Problems IICreative Solutions to Already Solved Problems II
Creative Solutions to Already Solved Problems II
 
Is writing performant code too expensive?
Is writing performant code too expensive? Is writing performant code too expensive?
Is writing performant code too expensive?
 
GDG Kuwait - Modern android development
GDG Kuwait - Modern android developmentGDG Kuwait - Modern android development
GDG Kuwait - Modern android development
 
2017: Kotlin - now more than ever
2017: Kotlin - now more than ever2017: Kotlin - now more than ever
2017: Kotlin - now more than ever
 
Grails EE
Grails EEGrails EE
Grails EE
 
GR8Conf 2011: GContracts
GR8Conf 2011: GContractsGR8Conf 2011: GContracts
GR8Conf 2011: GContracts
 
Effective codereview | Dave Liddament | CODEiD
Effective codereview | Dave Liddament | CODEiDEffective codereview | Dave Liddament | CODEiD
Effective codereview | Dave Liddament | CODEiD
 
Is writing performant code too expensive?
Is writing performant code too expensive? Is writing performant code too expensive?
Is writing performant code too expensive?
 
Little Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinLittle Helpers for Android Development with Kotlin
Little Helpers for Android Development with Kotlin
 
Anko - The Ultimate Ninja of Kotlin Libraries?
Anko - The Ultimate Ninja of Kotlin Libraries?Anko - The Ultimate Ninja of Kotlin Libraries?
Anko - The Ultimate Ninja of Kotlin Libraries?
 
Practices For Becoming A Better Programmer
Practices For Becoming A Better ProgrammerPractices For Becoming A Better Programmer
Practices For Becoming A Better Programmer
 
The road to continuous deployment (DomCode September 2016)
The road to continuous deployment (DomCode September 2016)The road to continuous deployment (DomCode September 2016)
The road to continuous deployment (DomCode September 2016)
 
Clean Code
Clean CodeClean Code
Clean Code
 
Coding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinCoding for Android on steroids with Kotlin
Coding for Android on steroids with Kotlin
 

Mehr von 哲偉 楊

Specification unit test by Spek
Specification unit test by SpekSpecification unit test by Spek
Specification unit test by Spek哲偉 楊
 
Code kata 的自我修煉
Code kata 的自我修煉Code kata 的自我修煉
Code kata 的自我修煉哲偉 楊
 
輕輕鬆鬆產生 changelog
輕輕鬆鬆產生 changelog輕輕鬆鬆產生 changelog
輕輕鬆鬆產生 changelog哲偉 楊
 
Speed up add custom marker on google map
Speed up add custom marker on google mapSpeed up add custom marker on google map
Speed up add custom marker on google map哲偉 楊
 
Jenkins for android developer at TWJUG
Jenkins for android developer at TWJUGJenkins for android developer at TWJUG
Jenkins for android developer at TWJUG哲偉 楊
 
自己的 Jenkins 自己來 for Android developer
自己的 Jenkins 自己來  for Android developer自己的 Jenkins 自己來  for Android developer
自己的 Jenkins 自己來 for Android developer哲偉 楊
 
從開發到上線的華麗大冒險
從開發到上線的華麗大冒險從開發到上線的華麗大冒險
從開發到上線的華麗大冒險哲偉 楊
 
Unit test and ui testing with cucumber
Unit test and ui testing with cucumberUnit test and ui testing with cucumber
Unit test and ui testing with cucumber哲偉 楊
 
RxJava With retrolambda
RxJava With retrolambdaRxJava With retrolambda
RxJava With retrolambda哲偉 楊
 
ORMLite Android
ORMLite AndroidORMLite Android
ORMLite Android哲偉 楊
 
設計師合作經驗分享
設計師合作經驗分享設計師合作經驗分享
設計師合作經驗分享哲偉 楊
 
Hybrid design with bootstrap
Hybrid design with bootstrapHybrid design with bootstrap
Hybrid design with bootstrap哲偉 楊
 

Mehr von 哲偉 楊 (16)

Specification unit test by Spek
Specification unit test by SpekSpecification unit test by Spek
Specification unit test by Spek
 
Code kata 的自我修煉
Code kata 的自我修煉Code kata 的自我修煉
Code kata 的自我修煉
 
Coding dojo
Coding dojoCoding dojo
Coding dojo
 
輕輕鬆鬆產生 changelog
輕輕鬆鬆產生 changelog輕輕鬆鬆產生 changelog
輕輕鬆鬆產生 changelog
 
Speed up add custom marker on google map
Speed up add custom marker on google mapSpeed up add custom marker on google map
Speed up add custom marker on google map
 
Spek
SpekSpek
Spek
 
Jenkins for android developer at TWJUG
Jenkins for android developer at TWJUGJenkins for android developer at TWJUG
Jenkins for android developer at TWJUG
 
自己的 Jenkins 自己來 for Android developer
自己的 Jenkins 自己來  for Android developer自己的 Jenkins 自己來  for Android developer
自己的 Jenkins 自己來 for Android developer
 
從開發到上線的華麗大冒險
從開發到上線的華麗大冒險從開發到上線的華麗大冒險
從開發到上線的華麗大冒險
 
Unit test and ui testing with cucumber
Unit test and ui testing with cucumberUnit test and ui testing with cucumber
Unit test and ui testing with cucumber
 
RxJava With retrolambda
RxJava With retrolambdaRxJava With retrolambda
RxJava With retrolambda
 
ORMLite Android
ORMLite AndroidORMLite Android
ORMLite Android
 
設計師合作經驗分享
設計師合作經驗分享設計師合作經驗分享
設計師合作經驗分享
 
Dog point
Dog pointDog point
Dog point
 
Gson
GsonGson
Gson
 
Hybrid design with bootstrap
Hybrid design with bootstrapHybrid design with bootstrap
Hybrid design with bootstrap
 

Kürzlich hochgeladen

Digital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptxDigital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptxMohamedFarag457087
 
Thyroid Physiology_Dr.E. Muralinath_ Associate Professor
Thyroid Physiology_Dr.E. Muralinath_ Associate ProfessorThyroid Physiology_Dr.E. Muralinath_ Associate Professor
Thyroid Physiology_Dr.E. Muralinath_ Associate Professormuralinath2
 
Site specific recombination and transposition.........pdf
Site specific recombination and transposition.........pdfSite specific recombination and transposition.........pdf
Site specific recombination and transposition.........pdfCherry
 
Cyanide resistant respiration pathway.pptx
Cyanide resistant respiration pathway.pptxCyanide resistant respiration pathway.pptx
Cyanide resistant respiration pathway.pptxCherry
 
Human genetics..........................pptx
Human genetics..........................pptxHuman genetics..........................pptx
Human genetics..........................pptxCherry
 
Genome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptxGenome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptxCherry
 
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIACURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIADr. TATHAGAT KHOBRAGADE
 
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryFAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryAlex Henderson
 
Bhiwandi Bhiwandi ❤CALL GIRL 7870993772 ❤CALL GIRLS ESCORT SERVICE In Bhiwan...
Bhiwandi Bhiwandi ❤CALL GIRL 7870993772 ❤CALL GIRLS  ESCORT SERVICE In Bhiwan...Bhiwandi Bhiwandi ❤CALL GIRL 7870993772 ❤CALL GIRLS  ESCORT SERVICE In Bhiwan...
Bhiwandi Bhiwandi ❤CALL GIRL 7870993772 ❤CALL GIRLS ESCORT SERVICE In Bhiwan...Monika Rani
 
FAIRSpectra - Enabling the FAIRification of Analytical Science
FAIRSpectra - Enabling the FAIRification of Analytical ScienceFAIRSpectra - Enabling the FAIRification of Analytical Science
FAIRSpectra - Enabling the FAIRification of Analytical ScienceAlex Henderson
 
Use of mutants in understanding seedling development.pptx
Use of mutants in understanding seedling development.pptxUse of mutants in understanding seedling development.pptx
Use of mutants in understanding seedling development.pptxRenuJangid3
 
Climate Change Impacts on Terrestrial and Aquatic Ecosystems.pptx
Climate Change Impacts on Terrestrial and Aquatic Ecosystems.pptxClimate Change Impacts on Terrestrial and Aquatic Ecosystems.pptx
Climate Change Impacts on Terrestrial and Aquatic Ecosystems.pptxDiariAli
 
Terpineol and it's characterization pptx
Terpineol and it's characterization pptxTerpineol and it's characterization pptx
Terpineol and it's characterization pptxMuhammadRazzaq31
 
Dr. E. Muralinath_ Blood indices_clinical aspects
Dr. E. Muralinath_ Blood indices_clinical  aspectsDr. E. Muralinath_ Blood indices_clinical  aspects
Dr. E. Muralinath_ Blood indices_clinical aspectsmuralinath2
 
Call Girls Ahmedabad +917728919243 call me Independent Escort Service
Call Girls Ahmedabad +917728919243 call me Independent Escort ServiceCall Girls Ahmedabad +917728919243 call me Independent Escort Service
Call Girls Ahmedabad +917728919243 call me Independent Escort Serviceshivanisharma5244
 
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....muralinath2
 
Role of AI in seed science Predictive modelling and Beyond.pptx
Role of AI in seed science  Predictive modelling and  Beyond.pptxRole of AI in seed science  Predictive modelling and  Beyond.pptx
Role of AI in seed science Predictive modelling and Beyond.pptxArvind Kumar
 
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bSérgio Sacani
 

Kürzlich hochgeladen (20)

Digital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptxDigital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptx
 
Thyroid Physiology_Dr.E. Muralinath_ Associate Professor
Thyroid Physiology_Dr.E. Muralinath_ Associate ProfessorThyroid Physiology_Dr.E. Muralinath_ Associate Professor
Thyroid Physiology_Dr.E. Muralinath_ Associate Professor
 
Site specific recombination and transposition.........pdf
Site specific recombination and transposition.........pdfSite specific recombination and transposition.........pdf
Site specific recombination and transposition.........pdf
 
Cyanide resistant respiration pathway.pptx
Cyanide resistant respiration pathway.pptxCyanide resistant respiration pathway.pptx
Cyanide resistant respiration pathway.pptx
 
Human genetics..........................pptx
Human genetics..........................pptxHuman genetics..........................pptx
Human genetics..........................pptx
 
Genome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptxGenome sequencing,shotgun sequencing.pptx
Genome sequencing,shotgun sequencing.pptx
 
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIACURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
 
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryFAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
 
Bhiwandi Bhiwandi ❤CALL GIRL 7870993772 ❤CALL GIRLS ESCORT SERVICE In Bhiwan...
Bhiwandi Bhiwandi ❤CALL GIRL 7870993772 ❤CALL GIRLS  ESCORT SERVICE In Bhiwan...Bhiwandi Bhiwandi ❤CALL GIRL 7870993772 ❤CALL GIRLS  ESCORT SERVICE In Bhiwan...
Bhiwandi Bhiwandi ❤CALL GIRL 7870993772 ❤CALL GIRLS ESCORT SERVICE In Bhiwan...
 
FAIRSpectra - Enabling the FAIRification of Analytical Science
FAIRSpectra - Enabling the FAIRification of Analytical ScienceFAIRSpectra - Enabling the FAIRification of Analytical Science
FAIRSpectra - Enabling the FAIRification of Analytical Science
 
Use of mutants in understanding seedling development.pptx
Use of mutants in understanding seedling development.pptxUse of mutants in understanding seedling development.pptx
Use of mutants in understanding seedling development.pptx
 
Climate Change Impacts on Terrestrial and Aquatic Ecosystems.pptx
Climate Change Impacts on Terrestrial and Aquatic Ecosystems.pptxClimate Change Impacts on Terrestrial and Aquatic Ecosystems.pptx
Climate Change Impacts on Terrestrial and Aquatic Ecosystems.pptx
 
Terpineol and it's characterization pptx
Terpineol and it's characterization pptxTerpineol and it's characterization pptx
Terpineol and it's characterization pptx
 
Dr. E. Muralinath_ Blood indices_clinical aspects
Dr. E. Muralinath_ Blood indices_clinical  aspectsDr. E. Muralinath_ Blood indices_clinical  aspects
Dr. E. Muralinath_ Blood indices_clinical aspects
 
Call Girls Ahmedabad +917728919243 call me Independent Escort Service
Call Girls Ahmedabad +917728919243 call me Independent Escort ServiceCall Girls Ahmedabad +917728919243 call me Independent Escort Service
Call Girls Ahmedabad +917728919243 call me Independent Escort Service
 
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
 
PATNA CALL GIRLS 8617370543 LOW PRICE ESCORT SERVICE
PATNA CALL GIRLS 8617370543 LOW PRICE ESCORT SERVICEPATNA CALL GIRLS 8617370543 LOW PRICE ESCORT SERVICE
PATNA CALL GIRLS 8617370543 LOW PRICE ESCORT SERVICE
 
Site Acceptance Test .
Site Acceptance Test                    .Site Acceptance Test                    .
Site Acceptance Test .
 
Role of AI in seed science Predictive modelling and Beyond.pptx
Role of AI in seed science  Predictive modelling and  Beyond.pptxRole of AI in seed science  Predictive modelling and  Beyond.pptx
Role of AI in seed science Predictive modelling and Beyond.pptx
 
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
 

Kotlin初體驗

  • 2. @2017 PKLOT CO., LTD ABOUT ME ▸ Andy ▸ @ 停⾞車車⼤大聲公 ▸ @ Android Developer 讀書會 (TADSG) ▸ @ Android Code Club (週三晚上)
  • 3. @2017 PKLOT CO., LTD 有⼈人聽過 KOTLIN 嗎?
  • 4. @2017 PKLOT CO., LTD 有⼈人⽤用過 KOTLIN 嗎?
  • 5. @2017 PKLOT CO., LTD HELLO KOTLIN ▸ JetBrains 開發的 JVM 語⾔言 ▸ 包含很多 Effective Java 的思想在裡⾯面 ▸ Java 開發者的夢幻語⾔言 ?!
  • 6. @2017 PKLOT CO., LTD WHY KOTLIN ▸ Short Code ▸ Null Safety ▸ Smart Cast ▸ Lambda (Functional Programing) ▸ Method Extension ▸ Hybrid with Java ▸ Default final ▸ Everything is Object
  • 7. @2017 PKLOT CO., LTD HOW KOTLIN ▸ Install Android Studio Plugin “Kotlin” ▸ cmd + shift + a -> Configure kotlin in Project ▸ classpth : “org.jetbrains.kotlin:lotlin-gradle-plugin:1.0.7” ▸ apply plugin: ‘kotlin-android’ ▸ compile ‘org.jetbrains.kotlin:kotlin-stdlib:1.0.7’
  • 8. @2017 PKLOT CO., LTD JAVA TO KOTLIN ▸ 遇到不知道如何表達的 kotlin 語法可以先透過轉換觀察 ▸ cmd + shift + a -> Convert Java File to Kotlin ▸ ⼀一鍵完成
  • 9. @2017 PKLOT CO., LTD KOTLIN FEATURE ▸ Multiple class in one file ▸ Data Class ▸ Properties val/var ▸ Null Safety ▸ Smart Cast ▸ Method Extension / infix ▸ Lambda ▸ Operator Overloading ▸ Companion object ▸ Delegate ▸ Dependency Injection
  • 10. @2017 PKLOT CO., LTD MULTIPLE CLASS IN ONE FILE ▸ Class 的整理理更更有彈性 ▸ 同質性⾼高且簡易易的 Class 可以放到⼀一起 ▸ 提⾼高閱讀,不易易中斷思考
  • 11. @2017 PKLOT CO., LTD DATA CLASS ▸ hashCode() ▸ toString() ▸ equals() ▸ with properties
  • 12. @2017 PKLOT CO., LTD PROPERTIES ▸ var(variable) ▸ var age (compile error) ▸ var age:Int (compile error) ▸ var age = 1 (ok) ▸ age = 2 (ok) ▸ age = null (ok) ▸ var myAge = age (ok)
  • 13. @2017 PKLOT CO., LTD PROPERTIES ▸ val(value) ▸ val age (compile error) ▸ val age:Int (compile error) ▸ val age = 18 (ok) ▸ age = 19 (compile error)
  • 14. @2017 PKLOT CO., LTD NULL SAFETY ▸ NullPointerException ▸ ? -> nullable, default non null ▸ var order : Order? = Order() ▸ order?.price (null safety if order is null) ▸ order.price (compile error)
  • 15. @2017 PKLOT CO., LTD SMART CASE ▸ ClassCastException ▸ Stupid Case if(exception instanceOf HttpException) { HttpException httpException = (HttpException) exception int code = httpException.getStatusCode(); }
  • 16. @2017 PKLOT CO., LTD SMART CASE ▸ Smart Case when(exception) { is HttpException -> { int code = exception.statusCode } default -> { // do something else } }
  • 17. @2017 PKLOT CO., LTD METHOD EXTENSION / INFIX ▸ Method Extension var name : String = null val isNull = name.isNullOrEmpty() ▸ In Java if(name == null || name.length == 0) StringUtils.isNullOrEmpty(name)
  • 18. @2017 PKLOT CO., LTD METHOD EXTENSION / INFIX ▸ How fun CharSequence?.isNullOrEmpty() : Boolean = this == null || this.lenght == 0
  • 19. @2017 PKLOT CO., LTD METHOD EXTENSION / INFIX ▸ Infix ▸ val isLike = “ABC” like “123-ABC” infix fun String.like(it: String) : Boolean = this.toUpperCase.contains(it) ▸ “name” to “Andy” mapOf( Pair(“nickName”, “andyang”), “name” to “Andy” )
  • 20. @2017 PKLOT CO., LTD LAMBDA ▸ 不必再等 Java 8 到天荒地老 ▸ 不⽤用 Retrolambda ▸ Kotlin 內建 lambda
  • 21. @2017 PKLOT CO., LTD LAMBDA ▸ setOnClickListener() view.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v){ Toast.makeToast(…..).show() } })
  • 22. @2017 PKLOT CO., LTD LAMBDA ▸ setOnClickListener() view.setOnClickListener({ view -> Toast.makeToast(…..).show() }) view.setOnClickListener({ Toast.makeToast(…..).show() })
  • 23. @2017 PKLOT CO., LTD LAMBDA ▸ setOnClickListener() view.setOnClickListener{ Toast.makeToast(…..).show()} view.onClick{ Toast.makeToast(…..).show()}
  • 24. @2017 PKLOT CO., LTD LAMBDA ▸ Adapter OnItemClickListener interface OnOrderItemClickListener{ onOrderItemClick(Order order); } OnOrderItemClickListener onOrderItemClickListener; ‣ interface, setter, init, invoke
  • 25. @2017 PKLOT CO., LTD LAMBDA ▸ Adapter OnItemClickListener in Kotlin var onOrderItemClickListener : (order: Order) -> Unit holder?.onClick{ onOrderItemClickListener.invoke(order) } holder?.onClick{ onOrderItemClickListener(order) }
  • 26. @2017 PKLOT CO., LTD OPERATOR OVERLOADING ▸ a == b -> a.equals(b) ▸ a + b -> a.plus(b) ▸ a - b, a * b, a / b, a % b ….. ▸ a..b -> a.rangeTo(b) ▸ a in b -> a.contains(b) ▸ a[i] -> a.get(i) ▸ a[i] = b -> a.set(i, b)
  • 27. @2017 PKLOT CO., LTD COMPANION OBJECT class App : Application() { companion object { private var instance: Application? = null fun instance() = instance } override fun onCreate() { super.onCreate(); instance = this } }
  • 28. @2017 PKLOT CO., LTD PROPERTISE DELEGATE class Delegate<T> : ReadWriteProperty<Any?, T> { override fun getValue(thisRef: Any?, property : KPropety<*>) { } override fun setValue(thisRef: Any?, property : KPropety<*>, value: T) { } } var name : String by Delegate()
  • 29. @2017 PKLOT CO., LTD PROPERTISE DELEGATE ‣ Demo Delegate SharedPreferences
  • 30. @2017 PKLOT CO., LTD DEPENDENCY INJECTION ‣ In MPV Pattern ‣ Presenter need inject Model ‣ Repository(NetworkService networkService, LocalData localData) ‣ LocalData(Content context) ‣ Presenter(View view, Repository repository)
  • 31. @2017 PKLOT CO., LTD DEPENDENCY INJECTION ‣ new Presenter ‣ In Java Presenter presenter = new Presenter(new Repository(new NetworkService(), new LocalData(context))); // so ugly Presenter presenter = PresenterFactory.create();
  • 32. @2017 PKLOT CO., LTD DEPENDENCY INJECTION ‣ In kotlin ‣ Repository(networkService : NetworkService = NetworkService(), localData : LocalData = LocalData()) ‣ LocalData(context : Content = App.instance()) ‣ Presenter(view : View, repository : Repository = Repository())
  • 33. @2017 PKLOT CO., LTD DEPENDENCY INJECTION ‣ In kotlin ‣ val presenter = Presenter(view) ‣ for testing ‣ val presenter = Presenter(view, mockRepository)
  • 34. @2017 PKLOT CO., LTD REFERENCE ▸ Kotlin official guide ▸ https://kotlinlang.org/docs/reference/ ▸ Kotlin For Android Developer (e-book) ▸ https://antonioleiva.com/kotlin-android-developers-book/
  • 35. @2017 PKLOT CO., LTD 學習⼀一⾨門語⾔言最快的⽅方式就是只能⽤用它!
  • 36. @2017 PKLOT CO., LTD Q&A @2017 PKLOT CO., LTD