SlideShare a Scribd company logo
Interface and Abstract Classes
Kotlin Study Group
John
Hi, I am John
- Android Developer
- Work on Rakuten Viki
- Use Kotlin for 2 years
- Linkedin:
https://www.linkedin.com/in/chang-john-0a95237a/
Outline
- Preface
- Interfaces
- Default Implementation
- Abstract Classes
- Difference
Preface
- Be aware the discrepancy of interface between Java(8 later and 8 prior) and Kotlin
- Be aware how to implement interface and abstract class between Java and Kotlin
- Be aware different between interface and abstract class in Kotlin
- Know about scenario of interface and abstract class usage
Interface - declaration
Interface - implementation
Interface - default implementation
Properties in interfaces
Computed Property
Property
Resolving overriding conflicts
default implementation
C only need to override bar because A already provide
default implementation
When interface has same signature function, whatever interface has default
implementation, D still override explicitly.
If D want to call default implementation, use super<T>.function(), like
super<A>.foo()
Discrepancy between Kotlin and Java
Kotlin Java 8 Java 8 prior
Field Final static via companion
object
Final static Final static
Property(field+accessor) Yes(but no backing field) No No
Function abstract/default/static abstract/default/static abstract
Abstract Classes
Difference
- Interface is stateless(they can’t have a state), abstract class is stateful(they can
have a state)
- An interface cannot specify a constructor.
- Interface can provide default implementation, but abstract function in abstract
class can’t have body
- A class can extend only one abstract class, but can implement many interface.
- From design view, interface is contract and abstract class is “is-a”

More Related Content

What's hot

Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementation
HoneyChintal
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
jehan1987
 
Java interfaces
Java   interfacesJava   interfaces
Java interfaces
Elizabeth alexander
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
Raja Sekhar
 
Interface java
Interface java Interface java
Interface java
atiafyrose
 
(3) c sharp introduction_basics_part_ii
(3) c sharp introduction_basics_part_ii(3) c sharp introduction_basics_part_ii
(3) c sharp introduction_basics_part_ii
Nico Ludwig
 
Java interface
Java interfaceJava interface
Java interface
BHUVIJAYAVELU
 
Interface Vs Abstact
Interface Vs AbstactInterface Vs Abstact
Interface Vs Abstact
Anand Kumar Rajana
 
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
New York City College of Technology Computer Systems Technology Colloquium
 
Abstract & Interface
Abstract & InterfaceAbstract & Interface
Abstract & Interface
Linh Lê
 
Final keyword
Final keywordFinal keyword
Final keyword
Namrata_Thakare
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Prof .Pragati Khade
 
interface in c#
interface in c#interface in c#
interface in c#
Deepti Pillai
 
Java interface
Java interfaceJava interface
Java interface
Md. Tanvir Hossain
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
Abishek Purushothaman
 
C language
C languageC language
C language
Arafat Bin Reza
 
Interfaces c#
Interfaces c#Interfaces c#
Interfaces c#
Nipam Medhi
 
Oracle pl/sql control statments
Oracle pl/sql control statmentsOracle pl/sql control statments
Oracle pl/sql control statments
Tayba Bashir
 
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Raffi Khatchadourian
 

What's hot (20)

Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementation
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Java interfaces
Java   interfacesJava   interfaces
Java interfaces
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Interface java
Interface java Interface java
Interface java
 
(3) c sharp introduction_basics_part_ii
(3) c sharp introduction_basics_part_ii(3) c sharp introduction_basics_part_ii
(3) c sharp introduction_basics_part_ii
 
Java interface
Java interfaceJava interface
Java interface
 
Interface Vs Abstact
Interface Vs AbstactInterface Vs Abstact
Interface Vs Abstact
 
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
 
Abstract & Interface
Abstract & InterfaceAbstract & Interface
Abstract & Interface
 
Final keyword
Final keywordFinal keyword
Final keyword
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
interface in c#
interface in c#interface in c#
interface in c#
 
Java interface
Java interfaceJava interface
Java interface
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
C language
C languageC language
C language
 
Interfaces c#
Interfaces c#Interfaces c#
Interfaces c#
 
Oracle pl/sql control statments
Oracle pl/sql control statmentsOracle pl/sql control statments
Oracle pl/sql control statments
 
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
 

Similar to Interface and abstract classes

Getting Started With Kotlin
Getting Started With KotlinGetting Started With Kotlin
Getting Started With Kotlin
Gaurav sharma
 
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor BuzatovićJavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Introduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTXIntroduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTX
Syed Awais Mazhar Bukhari
 
Objects
ObjectsObjects
Objects
Chang John
 
Compose Camp - Intro.pdf
Compose Camp - Intro.pdfCompose Camp - Intro.pdf
Compose Camp - Intro.pdf
ajaykumarpurohit
 
Java vs kotlin
Java vs kotlinJava vs kotlin
Java vs kotlin
Deesha Vora
 
Generic UXD Legos - Selenium Conference 2015
Generic UXD Legos - Selenium Conference 2015Generic UXD Legos - Selenium Conference 2015
Generic UXD Legos - Selenium Conference 2015
Selena Phillips
 
Jetpack compose
Jetpack composeJetpack compose
Jetpack compose
LutasLin
 
Try Jetpack Compose
Try Jetpack ComposeTry Jetpack Compose
Try Jetpack Compose
LutasLin
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
Saurabh Tripathi
 
Basics of kotlin ASJ
Basics of kotlin ASJBasics of kotlin ASJ
Basics of kotlin ASJ
DSCBVRITH
 
Kotlin Programming Language | Edureka
Kotlin Programming Language | EdurekaKotlin Programming Language | Edureka
Kotlin Programming Language | Edureka
Edureka!
 
6_VirtualFunctions_AbstractClasses.pdf
6_VirtualFunctions_AbstractClasses.pdf6_VirtualFunctions_AbstractClasses.pdf
6_VirtualFunctions_AbstractClasses.pdf
RamiDiab8
 
Kotlin Native - C / Swift Interop - ACCU Autmn 2019
Kotlin Native - C / Swift Interop - ACCU Autmn 2019Kotlin Native - C / Swift Interop - ACCU Autmn 2019
Kotlin Native - C / Swift Interop - ACCU Autmn 2019
Eamonn Boyle
 
Lecture 5 interface.pdf
Lecture  5 interface.pdfLecture  5 interface.pdf
Lecture 5 interface.pdf
AdilAijaz3
 
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
UA Mobile
 
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Eugene Kurko
 
Kotlin在android中的應用
Kotlin在android中的應用Kotlin在android中的應用
Kotlin在android中的應用
LutasLin
 
Defining classes
Defining classesDefining classes
Defining classes
Chang John
 
J interop
J interopJ interop
J interop
Muhammad Yousaf
 

Similar to Interface and abstract classes (20)

Getting Started With Kotlin
Getting Started With KotlinGetting Started With Kotlin
Getting Started With Kotlin
 
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor BuzatovićJavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
 
Introduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTXIntroduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTX
 
Objects
ObjectsObjects
Objects
 
Compose Camp - Intro.pdf
Compose Camp - Intro.pdfCompose Camp - Intro.pdf
Compose Camp - Intro.pdf
 
Java vs kotlin
Java vs kotlinJava vs kotlin
Java vs kotlin
 
Generic UXD Legos - Selenium Conference 2015
Generic UXD Legos - Selenium Conference 2015Generic UXD Legos - Selenium Conference 2015
Generic UXD Legos - Selenium Conference 2015
 
Jetpack compose
Jetpack composeJetpack compose
Jetpack compose
 
Try Jetpack Compose
Try Jetpack ComposeTry Jetpack Compose
Try Jetpack Compose
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
 
Basics of kotlin ASJ
Basics of kotlin ASJBasics of kotlin ASJ
Basics of kotlin ASJ
 
Kotlin Programming Language | Edureka
Kotlin Programming Language | EdurekaKotlin Programming Language | Edureka
Kotlin Programming Language | Edureka
 
6_VirtualFunctions_AbstractClasses.pdf
6_VirtualFunctions_AbstractClasses.pdf6_VirtualFunctions_AbstractClasses.pdf
6_VirtualFunctions_AbstractClasses.pdf
 
Kotlin Native - C / Swift Interop - ACCU Autmn 2019
Kotlin Native - C / Swift Interop - ACCU Autmn 2019Kotlin Native - C / Swift Interop - ACCU Autmn 2019
Kotlin Native - C / Swift Interop - ACCU Autmn 2019
 
Lecture 5 interface.pdf
Lecture  5 interface.pdfLecture  5 interface.pdf
Lecture 5 interface.pdf
 
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
 
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
 
Kotlin在android中的應用
Kotlin在android中的應用Kotlin在android中的應用
Kotlin在android中的應用
 
Defining classes
Defining classesDefining classes
Defining classes
 
J interop
J interopJ interop
J interop
 

More from Chang John

Whats resources compat_contextcompat_and_appcompat
Whats resources compat_contextcompat_and_appcompatWhats resources compat_contextcompat_and_appcompat
Whats resources compat_contextcompat_and_appcompat
Chang John
 
Inheritance
InheritanceInheritance
Inheritance
Chang John
 
Initialization
InitializationInitialization
Initialization
Chang John
 
Strings &amp; numbers
Strings &amp; numbersStrings &amp; numbers
Strings &amp; numbers
Chang John
 
Functions, anonymous functions and the function type
Functions, anonymous functions and the function typeFunctions, anonymous functions and the function type
Functions, anonymous functions and the function type
Chang John
 
Variables, constants, types, and conditionals
Variables, constants, types, and conditionalsVariables, constants, types, and conditionals
Variables, constants, types, and conditionals
Chang John
 
Google Play Instant: Improving User Engagement
Google Play Instant: Improving User EngagementGoogle Play Instant: Improving User Engagement
Google Play Instant: Improving User Engagement
Chang John
 

More from Chang John (7)

Whats resources compat_contextcompat_and_appcompat
Whats resources compat_contextcompat_and_appcompatWhats resources compat_contextcompat_and_appcompat
Whats resources compat_contextcompat_and_appcompat
 
Inheritance
InheritanceInheritance
Inheritance
 
Initialization
InitializationInitialization
Initialization
 
Strings &amp; numbers
Strings &amp; numbersStrings &amp; numbers
Strings &amp; numbers
 
Functions, anonymous functions and the function type
Functions, anonymous functions and the function typeFunctions, anonymous functions and the function type
Functions, anonymous functions and the function type
 
Variables, constants, types, and conditionals
Variables, constants, types, and conditionalsVariables, constants, types, and conditionals
Variables, constants, types, and conditionals
 
Google Play Instant: Improving User Engagement
Google Play Instant: Improving User EngagementGoogle Play Instant: Improving User Engagement
Google Play Instant: Improving User Engagement
 

Recently uploaded

sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
Ratnakar Mikkili
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 

Recently uploaded (20)

sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 

Interface and abstract classes

  • 1. Interface and Abstract Classes Kotlin Study Group John
  • 2. Hi, I am John - Android Developer - Work on Rakuten Viki - Use Kotlin for 2 years - Linkedin: https://www.linkedin.com/in/chang-john-0a95237a/
  • 3. Outline - Preface - Interfaces - Default Implementation - Abstract Classes - Difference
  • 4. Preface - Be aware the discrepancy of interface between Java(8 later and 8 prior) and Kotlin - Be aware how to implement interface and abstract class between Java and Kotlin - Be aware different between interface and abstract class in Kotlin - Know about scenario of interface and abstract class usage
  • 7. Interface - default implementation
  • 9. Resolving overriding conflicts default implementation C only need to override bar because A already provide default implementation When interface has same signature function, whatever interface has default implementation, D still override explicitly. If D want to call default implementation, use super<T>.function(), like super<A>.foo()
  • 10. Discrepancy between Kotlin and Java Kotlin Java 8 Java 8 prior Field Final static via companion object Final static Final static Property(field+accessor) Yes(but no backing field) No No Function abstract/default/static abstract/default/static abstract
  • 12. Difference - Interface is stateless(they can’t have a state), abstract class is stateful(they can have a state) - An interface cannot specify a constructor. - Interface can provide default implementation, but abstract function in abstract class can’t have body - A class can extend only one abstract class, but can implement many interface. - From design view, interface is contract and abstract class is “is-a”