SlideShare a Scribd company logo
Kotlin for Android
Erinda Jaupaj
@ErindaJaupi
SPECK
&
TECH
Few words about Kotlin
● Programming language
● Targets JVM, Android and Javascript
● Fully interoperable with Java
● Developed by Jetbrains
● https://kotlinlang.org/
Why do we need Kotlin
● Android is stuck on Java 6
○ No streams
○ No lambdas
○ No try-with-resources
Why do we need Kotlin
● Android is stuck on Java 6
○ No streams RxJava
○ No lambdas Retrolambda
○ No try-with-resources Retrolambda
Why do we need Kotlin
● Android is stuck on Java 6
● Java language restrictions
○ Nullability problems
○ Mutability problems
○ No way to add methods to types that we do not control
○ Too much verbosity
Avoid boilerplate
data class Person(
val name: String,
val surname: String,
var age: Int)
Create a POJO with:
● Getters
● Setters
● equals()
● hashCode()
● toString()
● copy()
Write more with less code
data class Person(
val name: String,, ,
val surname: String,,
var age: Int)
Create a POJO with:
● Getters
● Setters
● equals()
● hashCode()
● toString()
● copy()
public class Person {
final String firstName;
final String lastName;
public Person(...) {
...
}
// Getters
...
// Hashcode / equals
...
// Tostring
...
}
Mutability
An immutable object is an object whose state cannot be changed after instantiation.
val name = "Mary" // compile time error if we reassign it
var age = 20
Mutability
An immutable object is an object whose state cannot be changed after instantiation.
val name = "Mary" // compile time error if we reassign it
var age = 20
val numbers: MutableList = mutableListOf(1, 2, 3)
val readOnlyNumbers: List = numbers
Mutability
An immutable object is an object whose state cannot be changed after instantiation.
val name = "Mary" // compile time error if we reassign it
var age = 20
val numbers: MutableList = mutableListOf(1, 2, 3)
val readOnlyNumbers: List = numbers
numbers.clear()
readOnlyNumbers.clear() // does not compile
Nullability
Deal with possible null situations in compile time
Explicitly defines whether an object can be null by using the safe call operator (?)
var name: String? = "Mary"
name = null
name?.length
Extension functions
We can extend any class with new features even if we don’t have access to the source code
The extension function acts as part of the class
fun Int.isEven(): Boolean { return this%2 == 0 }
println("isEven ${4.isEven()}")
Extension functions
● do not modify the original class
● the function is added as a static import
● can be declared in any file
● common practice: create files which include a set of related functions
Interoperable
● Do not have to convert everything at once
● You can convert little portions
● Write kotlin code over the existing Java code
Kotlin Android Extension
Give direct access to all the views in XML
● it doesn’t add any extra libraries
● It’s a plugin that generates the code it needs to work only when it’s required, just by using the
standard Kotlin library
textView.text = "Hello, world!"
}
}
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("Hello, world!");
}
}
Anko
● powerful library developed by JetBrains
● main purpose is the generation of UI layouts by using code instead of XML
● avoid lots of boilerplate
○ navigation between activities
○ creation of fragments
○ database access
○ alerts creation
magic behind many Anko features => Extension functions
Dynamic Layout
scrollView {
linearLayout(LinearLayout.VERTICAL) {
val label = textView("?")
button("Click me!") {
label.setText("Clicked!")
}
editText("Edit me!")
}
}.style(...)
?
Click me!
Edit me!
Request out of the main thread
Anko provides a very easy DSL to deal with asynchrony
val url = "http://..."
doAsync() {
Request(url).run()
uiThread { longToast(“Request performed”) }
}
Request out of the main thread
Anko provides a very easy DSL to deal with asynchrony
val url = "http://..."
doAsync() {
Request(url).run()
uiThread { longToast(“Request perfomed”) }
}
Request(url).run()
class Request(val url: String) {
fun run() {
val forecastJsonStr = URL(url).readText()
Log.d(javaClass.simpleName, forecastJsonStr)
}
} // not recommended for huge responses
Object Oriented & Functional
Uses lambda expressions, to solve some problems in a much easier way.
view.setOnClickListener { toast("Hello world!") }
View view = (View) findViewById(R.id.view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText (this, "Hello world!", Toast.LENGTH_LONG )
.show();
}
});
A deeper look with an example
apply
● avoid the creation of builders
● the object that calls the function can initialise itself the way it needs,
● it will return the same object
val textView = TextView(context).apply {
text = "Hello"
hint = "Hint"
textColor = android.R.color.white
}
apply
enum class Orientation { VERTICAL, HORIZONTAL }
class LayoutStyle {
var orientation = HORIZONTAL
}
fun main(args: Array<String>) {
val layout = LayoutStyle().apply { orientation = VERTICAL }
}
enum Orientation { VERTICAL, HORIZONTAL; }
public class LayoutStyle {
private Orientation orientation = HORIZONTAL;
public Orientation getOrientation() {
return orientation;
}
public void setOrientation(Orientation orientation) {
this.orientation = orientation;
}
public static void main(String[] args) {
LayoutStyle layout = new LayoutStyle();
layout.setOrientation(VERTICAL);
}
}
apply
NEW LayoutStyle
DUP
INVOKESPECIAL LayoutStyle.<init> ()V
ASTORE 2
ALOAD 2
ASTORE 3
ALOAD 3
GETSTATIC Orientation.VERTICAL : LOrientation;
INVOKEVIRTUAL LayoutStyle.setOrientation (LOrientation;)V
ALOAD 2
ASTORE 1
NEW LayoutStyle
DUP
ASTORE 1
ALOAD 1
GETSTATIC Orientation.VERTICAL : Orientation;
INVOKEVIRTUAL LayoutStyle.setOrientation (Orientation;)V
apply
● Create a new instance of LayoutStyle and duplicate it on the stack
● Call the constructor with zero parameters
● Do a bunch of store/load
● Push the Orientation.VERTICAL value to the stack
● Invoke setOrientation, which pops the object and the value from the stack
Thank you!
https://antonioleiva.com/kotlin-android-developers-book/
https://www.youtube.com/watch?v=X1RVYt2QKQE
https://www.youtube.com/watch?v=H_oGi8uuDpA&list=PLGzvAU7OKxapj1YdCAjGv4ss9rqeMJMd4&index=3

More Related Content

What's hot (20)

PDF
Kotlin vs Java | Edureka
Edureka!
 
PDF
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Hardik Trivedi
 
PDF
Declarative UIs with Jetpack Compose
Ramon Ribeiro Rabello
 
KEY
Solid principles
Declan Whelan
 
PPTX
Kotlin Overview
Ekta Raj
 
PPTX
Kotlin on android
Kurt Renzo Acosta
 
PPTX
Kotlin Basics & Introduction to Jetpack Compose.pptx
takshilkunadia
 
PPTX
Introduction to Kotlin
T.M. Ishrak Hussain
 
PPTX
Introduction to Kotlin Language and its application to Android platform
EastBanc Tachnologies
 
PPTX
Kotlin
Ravi Pawar
 
PDF
Java Presentation For Syntax
PravinYalameli
 
PDF
Introduction to flutter
Wan Muzaffar Wan Hashim
 
PDF
REST APIs with Spring
Joshua Long
 
PPT
Java EE Introduction
ejlp12
 
PPT
The Kotlin Programming Language
intelliyole
 
PDF
Android Components
Aatul Palandurkar
 
PPTX
Jetpack Compose.pptx
GDSCVJTI
 
PDF
Try Jetpack Compose
LutasLin
 
PPTX
Kotlin InDepth Tutorial for beginners 2022
Simplilearn
 
Kotlin vs Java | Edureka
Edureka!
 
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Hardik Trivedi
 
Declarative UIs with Jetpack Compose
Ramon Ribeiro Rabello
 
Solid principles
Declan Whelan
 
Kotlin Overview
Ekta Raj
 
Kotlin on android
Kurt Renzo Acosta
 
Kotlin Basics & Introduction to Jetpack Compose.pptx
takshilkunadia
 
Introduction to Kotlin
T.M. Ishrak Hussain
 
Introduction to Kotlin Language and its application to Android platform
EastBanc Tachnologies
 
Kotlin
Ravi Pawar
 
Java Presentation For Syntax
PravinYalameli
 
Introduction to flutter
Wan Muzaffar Wan Hashim
 
REST APIs with Spring
Joshua Long
 
Java EE Introduction
ejlp12
 
The Kotlin Programming Language
intelliyole
 
Android Components
Aatul Palandurkar
 
Jetpack Compose.pptx
GDSCVJTI
 
Try Jetpack Compose
LutasLin
 
Kotlin InDepth Tutorial for beginners 2022
Simplilearn
 

Similar to Kotlin for Android Development (20)

PDF
Having Fun with Kotlin Android - DILo Surabaya
DILo Surabaya
 
PDF
Introduction to clojure
Abbas Raza
 
PDF
Kotlin for Android Developers - 1
Mohamed Nabil, MSc.
 
PDF
Poniendo Kotlin en producción a palos (Kotlin in production, the hard way)
Andrés Viedma Peláez
 
KEY
Ceylon - the language and its tools
Max Andersen
 
PPTX
Exploring Kotlin
Atiq Ur Rehman
 
PDF
Android 101 - Kotlin ( Future of Android Development)
Hassan Abid
 
PDF
Programming with Kotlin
David Gassner
 
PDF
Rapid Web API development with Kotlin and Ktor
Trayan Iliev
 
PPTX
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
Anna Brzezińska
 
PDF
Scala on-android
lifecoder
 
PDF
Clojure Small Intro
John Vlachoyiannis
 
PDF
Develop realtime web with Scala and Xitrum
Ngoc Dao
 
PDF
JavaOne 2016 - Kotlin: The Language of The Future For JVM?
Leonardo Zanivan
 
PPTX
JVM languages "flame wars"
Gal Marder
 
PPT
Java Basics
Sunil OS
 
PDF
Oscon Java Testing on the Fast Lane
Andres Almiray
 
PDF
Kotlin Developer Starter in Android projects
Bartosz Kosarzycki
 
PDF
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
STX Next
 
PDF
Davide Cerbo - Kotlin loves React - Codemotion Milan 2018
Codemotion
 
Having Fun with Kotlin Android - DILo Surabaya
DILo Surabaya
 
Introduction to clojure
Abbas Raza
 
Kotlin for Android Developers - 1
Mohamed Nabil, MSc.
 
Poniendo Kotlin en producción a palos (Kotlin in production, the hard way)
Andrés Viedma Peláez
 
Ceylon - the language and its tools
Max Andersen
 
Exploring Kotlin
Atiq Ur Rehman
 
Android 101 - Kotlin ( Future of Android Development)
Hassan Abid
 
Programming with Kotlin
David Gassner
 
Rapid Web API development with Kotlin and Ktor
Trayan Iliev
 
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
Anna Brzezińska
 
Scala on-android
lifecoder
 
Clojure Small Intro
John Vlachoyiannis
 
Develop realtime web with Scala and Xitrum
Ngoc Dao
 
JavaOne 2016 - Kotlin: The Language of The Future For JVM?
Leonardo Zanivan
 
JVM languages "flame wars"
Gal Marder
 
Java Basics
Sunil OS
 
Oscon Java Testing on the Fast Lane
Andres Almiray
 
Kotlin Developer Starter in Android projects
Bartosz Kosarzycki
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
STX Next
 
Davide Cerbo - Kotlin loves React - Codemotion Milan 2018
Codemotion
 
Ad

More from Speck&Tech (20)

PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PDF
Fai da te ed elettricità, con la bobina di Tesla!
Speck&Tech
 
PDF
DIY ed elettronica ai tempi dell’università
Speck&Tech
 
PDF
Sotto il letto, sopra il cloud: costruirsi un’infrastruttura da zero
Speck&Tech
 
PDF
Verze e diamanti: oltre le nanotecnologie
Speck&Tech
 
PDF
Respira, sei in Trentino! Monitorare l'invisibile
Speck&Tech
 
PDF
Cognitive Robotics: from Babies to Robots and AI
Speck&Tech
 
PDF
Edge AI: Bringing Intelligence to Embedded Devices
Speck&Tech
 
PDF
Genere e gioco da tavolo: il caso di "Free to Choose"
Speck&Tech
 
PDF
SPaRKLE: un rivelatore compatto di radiazioni spaziali, realizzato dagli stud...
Speck&Tech
 
PDF
Il ruolo degli stati alterati di coscienza e degli psichedelici nella terapia
Speck&Tech
 
PDF
Unity3D: Things you need to know to get started
Speck&Tech
 
PDF
Learning from Biometric Fingerprints to prevent Cyber Security Threats
Speck&Tech
 
PDF
How do we program a God? - Do the Androids dream of the electric sheep?
Speck&Tech
 
PDF
The bad, the ugly and the weird about IoT
Speck&Tech
 
PDF
Arduino is Hardware, Software, IoT and Community
Speck&Tech
 
PDF
Computational privacy: balancing privacy and utility in the digital era
Speck&Tech
 
PDF
Il trucco c'è (e si vede) - Beatrice Mautino
Speck&Tech
 
PDF
ScrapeGraphAI: AI-powered web scraping, reso facile con l'open source
Speck&Tech
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
Fai da te ed elettricità, con la bobina di Tesla!
Speck&Tech
 
DIY ed elettronica ai tempi dell’università
Speck&Tech
 
Sotto il letto, sopra il cloud: costruirsi un’infrastruttura da zero
Speck&Tech
 
Verze e diamanti: oltre le nanotecnologie
Speck&Tech
 
Respira, sei in Trentino! Monitorare l'invisibile
Speck&Tech
 
Cognitive Robotics: from Babies to Robots and AI
Speck&Tech
 
Edge AI: Bringing Intelligence to Embedded Devices
Speck&Tech
 
Genere e gioco da tavolo: il caso di "Free to Choose"
Speck&Tech
 
SPaRKLE: un rivelatore compatto di radiazioni spaziali, realizzato dagli stud...
Speck&Tech
 
Il ruolo degli stati alterati di coscienza e degli psichedelici nella terapia
Speck&Tech
 
Unity3D: Things you need to know to get started
Speck&Tech
 
Learning from Biometric Fingerprints to prevent Cyber Security Threats
Speck&Tech
 
How do we program a God? - Do the Androids dream of the electric sheep?
Speck&Tech
 
The bad, the ugly and the weird about IoT
Speck&Tech
 
Arduino is Hardware, Software, IoT and Community
Speck&Tech
 
Computational privacy: balancing privacy and utility in the digital era
Speck&Tech
 
Il trucco c'è (e si vede) - Beatrice Mautino
Speck&Tech
 
ScrapeGraphAI: AI-powered web scraping, reso facile con l'open source
Speck&Tech
 
Ad

Recently uploaded (20)

PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 

Kotlin for Android Development

  • 1. Kotlin for Android Erinda Jaupaj @ErindaJaupi SPECK & TECH
  • 2. Few words about Kotlin ● Programming language ● Targets JVM, Android and Javascript ● Fully interoperable with Java ● Developed by Jetbrains ● https://kotlinlang.org/
  • 3. Why do we need Kotlin ● Android is stuck on Java 6 ○ No streams ○ No lambdas ○ No try-with-resources
  • 4. Why do we need Kotlin ● Android is stuck on Java 6 ○ No streams RxJava ○ No lambdas Retrolambda ○ No try-with-resources Retrolambda
  • 5. Why do we need Kotlin ● Android is stuck on Java 6 ● Java language restrictions ○ Nullability problems ○ Mutability problems ○ No way to add methods to types that we do not control ○ Too much verbosity
  • 6. Avoid boilerplate data class Person( val name: String, val surname: String, var age: Int) Create a POJO with: ● Getters ● Setters ● equals() ● hashCode() ● toString() ● copy()
  • 7. Write more with less code data class Person( val name: String,, , val surname: String,, var age: Int) Create a POJO with: ● Getters ● Setters ● equals() ● hashCode() ● toString() ● copy() public class Person { final String firstName; final String lastName; public Person(...) { ... } // Getters ... // Hashcode / equals ... // Tostring ... }
  • 8. Mutability An immutable object is an object whose state cannot be changed after instantiation. val name = "Mary" // compile time error if we reassign it var age = 20
  • 9. Mutability An immutable object is an object whose state cannot be changed after instantiation. val name = "Mary" // compile time error if we reassign it var age = 20 val numbers: MutableList = mutableListOf(1, 2, 3) val readOnlyNumbers: List = numbers
  • 10. Mutability An immutable object is an object whose state cannot be changed after instantiation. val name = "Mary" // compile time error if we reassign it var age = 20 val numbers: MutableList = mutableListOf(1, 2, 3) val readOnlyNumbers: List = numbers numbers.clear() readOnlyNumbers.clear() // does not compile
  • 11. Nullability Deal with possible null situations in compile time Explicitly defines whether an object can be null by using the safe call operator (?) var name: String? = "Mary" name = null name?.length
  • 12. Extension functions We can extend any class with new features even if we don’t have access to the source code The extension function acts as part of the class fun Int.isEven(): Boolean { return this%2 == 0 } println("isEven ${4.isEven()}")
  • 13. Extension functions ● do not modify the original class ● the function is added as a static import ● can be declared in any file ● common practice: create files which include a set of related functions
  • 14. Interoperable ● Do not have to convert everything at once ● You can convert little portions ● Write kotlin code over the existing Java code
  • 15. Kotlin Android Extension Give direct access to all the views in XML ● it doesn’t add any extra libraries ● It’s a plugin that generates the code it needs to work only when it’s required, just by using the standard Kotlin library textView.text = "Hello, world!" } } TextView textView = (TextView) findViewById(R.id.textView); textView.setText("Hello, world!"); } }
  • 16. Anko ● powerful library developed by JetBrains ● main purpose is the generation of UI layouts by using code instead of XML ● avoid lots of boilerplate ○ navigation between activities ○ creation of fragments ○ database access ○ alerts creation magic behind many Anko features => Extension functions
  • 17. Dynamic Layout scrollView { linearLayout(LinearLayout.VERTICAL) { val label = textView("?") button("Click me!") { label.setText("Clicked!") } editText("Edit me!") } }.style(...) ? Click me! Edit me!
  • 18. Request out of the main thread Anko provides a very easy DSL to deal with asynchrony val url = "http://..." doAsync() { Request(url).run() uiThread { longToast(“Request performed”) } }
  • 19. Request out of the main thread Anko provides a very easy DSL to deal with asynchrony val url = "http://..." doAsync() { Request(url).run() uiThread { longToast(“Request perfomed”) } }
  • 20. Request(url).run() class Request(val url: String) { fun run() { val forecastJsonStr = URL(url).readText() Log.d(javaClass.simpleName, forecastJsonStr) } } // not recommended for huge responses
  • 21. Object Oriented & Functional Uses lambda expressions, to solve some problems in a much easier way. view.setOnClickListener { toast("Hello world!") } View view = (View) findViewById(R.id.view); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText (this, "Hello world!", Toast.LENGTH_LONG ) .show(); } });
  • 22. A deeper look with an example
  • 23. apply ● avoid the creation of builders ● the object that calls the function can initialise itself the way it needs, ● it will return the same object val textView = TextView(context).apply { text = "Hello" hint = "Hint" textColor = android.R.color.white }
  • 24. apply enum class Orientation { VERTICAL, HORIZONTAL } class LayoutStyle { var orientation = HORIZONTAL } fun main(args: Array<String>) { val layout = LayoutStyle().apply { orientation = VERTICAL } } enum Orientation { VERTICAL, HORIZONTAL; } public class LayoutStyle { private Orientation orientation = HORIZONTAL; public Orientation getOrientation() { return orientation; } public void setOrientation(Orientation orientation) { this.orientation = orientation; } public static void main(String[] args) { LayoutStyle layout = new LayoutStyle(); layout.setOrientation(VERTICAL); } }
  • 25. apply NEW LayoutStyle DUP INVOKESPECIAL LayoutStyle.<init> ()V ASTORE 2 ALOAD 2 ASTORE 3 ALOAD 3 GETSTATIC Orientation.VERTICAL : LOrientation; INVOKEVIRTUAL LayoutStyle.setOrientation (LOrientation;)V ALOAD 2 ASTORE 1 NEW LayoutStyle DUP ASTORE 1 ALOAD 1 GETSTATIC Orientation.VERTICAL : Orientation; INVOKEVIRTUAL LayoutStyle.setOrientation (Orientation;)V
  • 26. apply ● Create a new instance of LayoutStyle and duplicate it on the stack ● Call the constructor with zero parameters ● Do a bunch of store/load ● Push the Orientation.VERTICAL value to the stack ● Invoke setOrientation, which pops the object and the value from the stack