SlideShare a Scribd company logo
Kotlin Programming Language
Tanikin Yeldos
1
Content
1. Why Kotlin?
2. Features of Kotlin
3. Benefits of using Kotlin
4. Efforts to use Kotlin
5. Kotlin integration scenarios to a project
6. Q&A
2
3
WHY NOT GROOVY?
4
WHY NOT SCALA?
● Statically typed
● 100% Interoperable with Java
● Fast learning curve (way simpler than Scala)
● Good tooling in IDEs
● Concise
● Familiar syntax and environments
● Over hundreds of important language constructions
Why Kotlin ?
5
Features of Kotlin
6
Properties (1)
7
fun typesExample() {
bigDecimal.add(projectName) /* Compile time Error */
}
Type inference
var projectName = "RoadLog"
val bigDecimal = BigDecimal.TEN
public class Person {
private String name;
private int age;
public Bar(String Name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String Name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
class Person(var name: String, var age: Int)
Properties (2)
8
Class in single line
Custom setter/getter
Properties (3)
class Money {
var amount = BigDecimal.ZERO
get() {
return if (field >= BigDecimal.ZERO) field else BigDecimal.ONE
}
set(value) {
field = value + BigDecimal.TEN
}
//Accessor will invoke automatically when you assign value
Money.amount = BigDecimal.valueOf(-200)
var amount = money.amount
9
Interoperable in properties
Properties (4)
10
val exampleJavaClass = ExampleJavaClass()
exampleJavaClass.value = BigDecimal.ONE
exampleJavaClass.currency = "EUR"
val currency = exampleJavaClass.currency
Project project= new Project("RoadLog", 4);
String name = project.getName();
project.setAge(5);
class Project(var name: String, var age: Int)
Functions (1)
Default parameters come in handy (optional arguments)
public void setManyParameters() {
setManyParameters("name");
}
fun setManyParameters(name: String= "name", age: Int = 18, weight: Int = 50) {
}
11
public void setManyParameters(String name, int age, int weight) {
// Do something
}
public void setManyParameters(String name, int age) {
setManyParameters(name, age, 50);
}
public void setManyParameters(String name) {
setManyParameters(name, 18);
}
Functions(2)
Order of parameters, not important
setManyParameters(age = 19)
fun setManyParameters(name: String= "name", age: Int = 18, weight: Int = 50) {
// Do something
}
12
setManyParameters(19)
Integer.parseInt(radix = 7, number = "100")
Lambda
Lambda as first class invoke just with round bracket, not apply, run, call etc.
13
fun getFilteredNumber(numbers: List<String>, prefix: String, predicate: (String, String) -> Boolean): List<String> {
return users.filter { predicate(it, prefix) }
}
public List<String> getFilteredNumber(List<String> numbers, String prefix, BiFunction<String, String, Boolean> predicate) {
return numbers.stream()
.filter(s -> predicate.apply(s, prefix))
.collect(Collectors.toList());
}
14
DEMO
Functions (4)
Best way for naming test method
15
@Test
fun `shoudn't be empty when amount is valid`() {
// Check something
}
@Test
fun `should create billing info for groupage shipment`() {
// Check something
}
String in Kotlin
String templates are String literals that contain embedded expressions
16
public void printSum(int firstNumber, int secondNumber) {
println("sum of " + firstNumber+ " and " + secondNumber+ " is " + (firstNumber + secondNumber));
}
fun printSum(firstNumber: Int, secondNumber: Int): Unit {
println("sum of $firstNumber and $secondNumber is ${firstNumber + secondNumber}")
}
Singleton
Singleton in single line
17
public class SingletonJava {
private static SingletonJava instance = null;
private SingletonJava (){}
private synchronized static void createInstance() {
if (instance == null) {
instance = new SingletonJava ();
}
}
public static SingletonJava getInstance() {
if (instance == null) {
createInstance();
}
return instance;
}
}
object SingletonKotlin {}
Collections
Really read-only collections by default
18
val numbers = listOf("one", "two", "three", "four", "five")
print(numbers[2])
numbers.add(3) // compile time error
numbers[2] = "six" // compile time error
List<Object> numberList = new ArrayList<>();
// adding few values to the list in a few lines((
List<Object> unmodifiableList = Collections.unmodifiableList(numberList);
unmodifiableList.add("one"); // not errors((
val mutableCollection = mutableListOf("one", "two");
mutableCollection.add("three") // OK
mutableCollection[6] = "four" // OK
val numbersMap = mapOf(1 to "one", 2 to "two", 3 to "three")
numbersMap.put(4, "four") // compile time error
numbersMap[4] = "four" // compile time error
Operator overriding
Any operator can be overridden
19
if (amount < 0.b) {
throw IllegalArgumentException()
}
val amount = 1.b
if (amount in 1.b..100.b) { // in 1.b..100.b equivalent of 1 <= amount && amount <= 100
return amount + 1000.b
}
class Money(var amount: BigDecimal, var currency: String) {
operator fun plus(value: BigDecimal): Money {
return Money(amount + value, currency)
}
}
Type-safe builder
Great replacement for the builder
20
class Person(var name: String = "Jack", var age: Int = 21, val students: MutableList<Person> = ArrayList()) {
fun student(init: Person.() -> Unit) = Person().also {
it.init()
students.add(it)
}
}
fun person(init: Person.() -> Unit) = Person().apply { init() }
val teacher= person {
name = "Jack"
age = 75
student {
name = "John"
age = 10
}
student {
name = "Gaga"
age = 11
}
}
Type-safe builder
Great replacement for the builder
21
val teacher= person {
name = "Jack"
age = 75
student {
name = "John"
age = 10
}
student {
name = "Gaga"
age = 11
}
}
Person teacher= PersonBuilder.buider()
.withName("Jack")
.withAge(75)
.withStudents(Lists.of(PersonBuilder.buider()
.withName("John")
.withAge(10)
.build(),
PersonBuilder.buider()
.withName("Gaga")
.withAge(11)
.build()))
.build()
1. Legacy code can remain untouched
2. Development productivity increase
a. Less writing
b. Less code reading (we read more than write)
c. Less code for reviewing
3. Code-base grows, Kotlin is easy for monorepo(git pull, status etc)
4. More understandable and cleaner code
5. The language is less error-prone
6. Less code - cheaper support
7. Interesting for developers
8. Attractive for new candidates
Benefits for RoadLOG
What are the benefits we can get
22
Risks
Language support in the future
23
24
25
Efforts
The efforts that is required of us
26
● Add one dependency and one plugin to pom.xml
● Set up SonarQube
● Install the IDE plugin
Kotlin integration plan
27
● For tariff component only, at first time
● Parallel coexistence
What skipped
Don’t have enough time to tell
28
● Coroutines
● Improved @Deprecated in Kotlin
● with, apply, let, run methods
● Data classes
● Sealed classes
● Destructing declarations val (name, age) = getUserByName();
● Inline functions
● Elvis (name ?: "name is empty")
● Kotlin DSL(already can be used in Gradle, because it’s type safety unlike groovy)
● Range in for
● Improved “when” (switch in java )
● Smart casting you don’t need cast after checking by “is” (instanceof)
● Access modifier internal
● …and lot more
Q&A
29
“if” like expression
try, when, if can be used as expression and return result
30
val max = if (firstValue > secondValue) {
println("choose firstValue")
firstValue
} else {
println("choose secondValue")
secondValue
}
return if (firstValue > secondValue) {
firstValue
} else {
secondValue
}
“when”
“switch” with range expression
31
val primeNumbers= listOf(1, 37, 73)
val x = 100
when (x) {
6, 700 -> print("== 6 or == 700")
in 1..10 -> print("x is in the range 1 to 10")
in primeNumbers-> print("best prime number")
!in 10..20 -> print("x is outside the range")
else -> print("none of the above")
}

More Related Content

PPTX
Kotlin Basic & Android Programming
Kongu Engineering College, Perundurai, Erode
 
PPTX
Kotlin
Ahmad Mahagna
 
PDF
Introduction to kotlin
NAVER Engineering
 
PDF
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Hardik Trivedi
 
PDF
Introduction to QML
Alan Uthoff
 
PDF
02 - Basics of Qt
Andreas Jakl
 
PPTX
Android with kotlin course
Abdul Rahman Masri Attal
 
Kotlin Basic & Android Programming
Kongu Engineering College, Perundurai, Erode
 
Introduction to kotlin
NAVER Engineering
 
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Hardik Trivedi
 
Introduction to QML
Alan Uthoff
 
02 - Basics of Qt
Andreas Jakl
 
Android with kotlin course
Abdul Rahman Masri Attal
 

What's hot (20)

PPT
The Kotlin Programming Language
intelliyole
 
PDF
A quick and fast intro to Kotlin
XPeppers
 
PPSX
Kotlin Language powerpoint show file
Saurabh Tripathi
 
PPTX
Introduction to Koltin for Android Part I
Atif AbbAsi
 
PPTX
Best Practices in Qt Quick/QML - Part I
ICS
 
PPTX
Intro to kotlin
Tomislav Homan
 
PPTX
Introduction to Qt
Puja Pramudya
 
PDF
In-Depth Model/View with QML
ICS
 
PDF
Best Practices in Qt Quick/QML - Part 1 of 4
ICS
 
PDF
OOP and FP
Mario Fusco
 
PPTX
Introduction to Kotlin
T.M. Ishrak Hussain
 
PDF
Hosting Your Own OTA Update Service
Quinlan Jung
 
PPTX
Kotlin InDepth Tutorial for beginners 2022
Simplilearn
 
PPTX
Qt test framework
ICS
 
PPTX
Kotlin presentation
MobileAcademy
 
PPTX
Hello, QML
Jack Yang
 
PDF
Kotlin vs Java | Edureka
Edureka!
 
PDF
Kotlin for Android Development
Speck&Tech
 
PDF
Idiomatic Kotlin
intelliyole
 
PDF
[2021] kotlin built-in higher-order functions
Wei-Shen Lu
 
The Kotlin Programming Language
intelliyole
 
A quick and fast intro to Kotlin
XPeppers
 
Kotlin Language powerpoint show file
Saurabh Tripathi
 
Introduction to Koltin for Android Part I
Atif AbbAsi
 
Best Practices in Qt Quick/QML - Part I
ICS
 
Intro to kotlin
Tomislav Homan
 
Introduction to Qt
Puja Pramudya
 
In-Depth Model/View with QML
ICS
 
Best Practices in Qt Quick/QML - Part 1 of 4
ICS
 
OOP and FP
Mario Fusco
 
Introduction to Kotlin
T.M. Ishrak Hussain
 
Hosting Your Own OTA Update Service
Quinlan Jung
 
Kotlin InDepth Tutorial for beginners 2022
Simplilearn
 
Qt test framework
ICS
 
Kotlin presentation
MobileAcademy
 
Hello, QML
Jack Yang
 
Kotlin vs Java | Edureka
Edureka!
 
Kotlin for Android Development
Speck&Tech
 
Idiomatic Kotlin
intelliyole
 
[2021] kotlin built-in higher-order functions
Wei-Shen Lu
 
Ad

Similar to Kotlin (20)

PPTX
K is for Kotlin
TechMagic
 
PDF
Develop your next app with kotlin @ AndroidMakersFr 2017
Arnaud Giuliani
 
PDF
Intro to Kotlin
Magda Miu
 
PDF
Privet Kotlin (Windy City DevFest)
Cody Engel
 
PDF
Kotlin, smarter development for the jvm
Arnaud Giuliani
 
PDF
Kotlin for Android Developers
Hassan Abid
 
PDF
Having Fun with Kotlin Android - DILo Surabaya
DILo Surabaya
 
PDF
Introduction to Kotlin
Patrick Yin
 
PPTX
Hello kotlin | An Event by DSC Unideb
Muhammad Raza
 
PDF
Kotlin: A pragmatic language by JetBrains
Jigar Gosar
 
PDF
Kotlin: forse è la volta buona (Trento)
Davide Cerbo
 
PDF
First few months with Kotlin - Introduction through android examples
Nebojša Vukšić
 
PDF
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
STX Next
 
PDF
Kotlin Developer Starter in Android projects
Bartosz Kosarzycki
 
PDF
Let's fly to the Kotlin Island. Just an introduction to Kotlin
Aliaksei Zhynhiarouski
 
PPTX
Introduction to Kotlin Language and its application to Android platform
EastBanc Tachnologies
 
PDF
Kotlin @ Devoxx 2011
Andrey Breslav
 
PDF
Kotlin Slides from Devoxx 2011
Andrey Breslav
 
PDF
Kotlin Introduction with Android applications
Thao Huynh Quang
 
PDF
Exploring Kotlin
Johan Haleby
 
K is for Kotlin
TechMagic
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Arnaud Giuliani
 
Intro to Kotlin
Magda Miu
 
Privet Kotlin (Windy City DevFest)
Cody Engel
 
Kotlin, smarter development for the jvm
Arnaud Giuliani
 
Kotlin for Android Developers
Hassan Abid
 
Having Fun with Kotlin Android - DILo Surabaya
DILo Surabaya
 
Introduction to Kotlin
Patrick Yin
 
Hello kotlin | An Event by DSC Unideb
Muhammad Raza
 
Kotlin: A pragmatic language by JetBrains
Jigar Gosar
 
Kotlin: forse è la volta buona (Trento)
Davide Cerbo
 
First few months with Kotlin - Introduction through android examples
Nebojša Vukšić
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
STX Next
 
Kotlin Developer Starter in Android projects
Bartosz Kosarzycki
 
Let's fly to the Kotlin Island. Just an introduction to Kotlin
Aliaksei Zhynhiarouski
 
Introduction to Kotlin Language and its application to Android platform
EastBanc Tachnologies
 
Kotlin @ Devoxx 2011
Andrey Breslav
 
Kotlin Slides from Devoxx 2011
Andrey Breslav
 
Kotlin Introduction with Android applications
Thao Huynh Quang
 
Exploring Kotlin
Johan Haleby
 
Ad

Recently uploaded (20)

PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Software Development Methodologies in 2025
KodekX
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
The Future of Artificial Intelligence (AI)
Mukul
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 

Kotlin

  • 2. Content 1. Why Kotlin? 2. Features of Kotlin 3. Benefits of using Kotlin 4. Efforts to use Kotlin 5. Kotlin integration scenarios to a project 6. Q&A 2
  • 5. ● Statically typed ● 100% Interoperable with Java ● Fast learning curve (way simpler than Scala) ● Good tooling in IDEs ● Concise ● Familiar syntax and environments ● Over hundreds of important language constructions Why Kotlin ? 5
  • 7. Properties (1) 7 fun typesExample() { bigDecimal.add(projectName) /* Compile time Error */ } Type inference var projectName = "RoadLog" val bigDecimal = BigDecimal.TEN
  • 8. public class Person { private String name; private int age; public Bar(String Name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public void setName(String Name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } } class Person(var name: String, var age: Int) Properties (2) 8 Class in single line
  • 9. Custom setter/getter Properties (3) class Money { var amount = BigDecimal.ZERO get() { return if (field >= BigDecimal.ZERO) field else BigDecimal.ONE } set(value) { field = value + BigDecimal.TEN } //Accessor will invoke automatically when you assign value Money.amount = BigDecimal.valueOf(-200) var amount = money.amount 9
  • 10. Interoperable in properties Properties (4) 10 val exampleJavaClass = ExampleJavaClass() exampleJavaClass.value = BigDecimal.ONE exampleJavaClass.currency = "EUR" val currency = exampleJavaClass.currency Project project= new Project("RoadLog", 4); String name = project.getName(); project.setAge(5); class Project(var name: String, var age: Int)
  • 11. Functions (1) Default parameters come in handy (optional arguments) public void setManyParameters() { setManyParameters("name"); } fun setManyParameters(name: String= "name", age: Int = 18, weight: Int = 50) { } 11 public void setManyParameters(String name, int age, int weight) { // Do something } public void setManyParameters(String name, int age) { setManyParameters(name, age, 50); } public void setManyParameters(String name) { setManyParameters(name, 18); }
  • 12. Functions(2) Order of parameters, not important setManyParameters(age = 19) fun setManyParameters(name: String= "name", age: Int = 18, weight: Int = 50) { // Do something } 12 setManyParameters(19) Integer.parseInt(radix = 7, number = "100")
  • 13. Lambda Lambda as first class invoke just with round bracket, not apply, run, call etc. 13 fun getFilteredNumber(numbers: List<String>, prefix: String, predicate: (String, String) -> Boolean): List<String> { return users.filter { predicate(it, prefix) } } public List<String> getFilteredNumber(List<String> numbers, String prefix, BiFunction<String, String, Boolean> predicate) { return numbers.stream() .filter(s -> predicate.apply(s, prefix)) .collect(Collectors.toList()); }
  • 15. Functions (4) Best way for naming test method 15 @Test fun `shoudn't be empty when amount is valid`() { // Check something } @Test fun `should create billing info for groupage shipment`() { // Check something }
  • 16. String in Kotlin String templates are String literals that contain embedded expressions 16 public void printSum(int firstNumber, int secondNumber) { println("sum of " + firstNumber+ " and " + secondNumber+ " is " + (firstNumber + secondNumber)); } fun printSum(firstNumber: Int, secondNumber: Int): Unit { println("sum of $firstNumber and $secondNumber is ${firstNumber + secondNumber}") }
  • 17. Singleton Singleton in single line 17 public class SingletonJava { private static SingletonJava instance = null; private SingletonJava (){} private synchronized static void createInstance() { if (instance == null) { instance = new SingletonJava (); } } public static SingletonJava getInstance() { if (instance == null) { createInstance(); } return instance; } } object SingletonKotlin {}
  • 18. Collections Really read-only collections by default 18 val numbers = listOf("one", "two", "three", "four", "five") print(numbers[2]) numbers.add(3) // compile time error numbers[2] = "six" // compile time error List<Object> numberList = new ArrayList<>(); // adding few values to the list in a few lines(( List<Object> unmodifiableList = Collections.unmodifiableList(numberList); unmodifiableList.add("one"); // not errors(( val mutableCollection = mutableListOf("one", "two"); mutableCollection.add("three") // OK mutableCollection[6] = "four" // OK val numbersMap = mapOf(1 to "one", 2 to "two", 3 to "three") numbersMap.put(4, "four") // compile time error numbersMap[4] = "four" // compile time error
  • 19. Operator overriding Any operator can be overridden 19 if (amount < 0.b) { throw IllegalArgumentException() } val amount = 1.b if (amount in 1.b..100.b) { // in 1.b..100.b equivalent of 1 <= amount && amount <= 100 return amount + 1000.b } class Money(var amount: BigDecimal, var currency: String) { operator fun plus(value: BigDecimal): Money { return Money(amount + value, currency) } }
  • 20. Type-safe builder Great replacement for the builder 20 class Person(var name: String = "Jack", var age: Int = 21, val students: MutableList<Person> = ArrayList()) { fun student(init: Person.() -> Unit) = Person().also { it.init() students.add(it) } } fun person(init: Person.() -> Unit) = Person().apply { init() } val teacher= person { name = "Jack" age = 75 student { name = "John" age = 10 } student { name = "Gaga" age = 11 } }
  • 21. Type-safe builder Great replacement for the builder 21 val teacher= person { name = "Jack" age = 75 student { name = "John" age = 10 } student { name = "Gaga" age = 11 } } Person teacher= PersonBuilder.buider() .withName("Jack") .withAge(75) .withStudents(Lists.of(PersonBuilder.buider() .withName("John") .withAge(10) .build(), PersonBuilder.buider() .withName("Gaga") .withAge(11) .build())) .build()
  • 22. 1. Legacy code can remain untouched 2. Development productivity increase a. Less writing b. Less code reading (we read more than write) c. Less code for reviewing 3. Code-base grows, Kotlin is easy for monorepo(git pull, status etc) 4. More understandable and cleaner code 5. The language is less error-prone 6. Less code - cheaper support 7. Interesting for developers 8. Attractive for new candidates Benefits for RoadLOG What are the benefits we can get 22
  • 23. Risks Language support in the future 23
  • 24. 24
  • 25. 25
  • 26. Efforts The efforts that is required of us 26 ● Add one dependency and one plugin to pom.xml ● Set up SonarQube ● Install the IDE plugin
  • 27. Kotlin integration plan 27 ● For tariff component only, at first time ● Parallel coexistence
  • 28. What skipped Don’t have enough time to tell 28 ● Coroutines ● Improved @Deprecated in Kotlin ● with, apply, let, run methods ● Data classes ● Sealed classes ● Destructing declarations val (name, age) = getUserByName(); ● Inline functions ● Elvis (name ?: "name is empty") ● Kotlin DSL(already can be used in Gradle, because it’s type safety unlike groovy) ● Range in for ● Improved “when” (switch in java ) ● Smart casting you don’t need cast after checking by “is” (instanceof) ● Access modifier internal ● …and lot more
  • 30. “if” like expression try, when, if can be used as expression and return result 30 val max = if (firstValue > secondValue) { println("choose firstValue") firstValue } else { println("choose secondValue") secondValue } return if (firstValue > secondValue) { firstValue } else { secondValue }
  • 31. “when” “switch” with range expression 31 val primeNumbers= listOf(1, 37, 73) val x = 100 when (x) { 6, 700 -> print("== 6 or == 700") in 1..10 -> print("x is in the range 1 to 10") in primeNumbers-> print("best prime number") !in 10..20 -> print("x is outside the range") else -> print("none of the above") }

Editor's Notes

  • #3: This is what we'll talk about Why Kotlin? Features of Kotlin, I will show some features(фичес) of Kotlin in a few slides Benefits of using Kotlin in a project Efforts that are required from us to use kotlin Kotlin integration Q&A May be you will have question and suggestions if you have questions please keep it at the end of the slide, otherwise we may not meet this time,
  • #15: right, extension functions For showing this feature let’s switch to the IDE LIVE CODING Often, you need to extend a class with new functionality. /////////////In most programming languages, you either create a new class or use some kind of design pattern to do this. There are a few things that are not nice with BigDecimal in java First one - How stream supports BigDecimal, or rather not at all The Second one, that is not nice with BigDecimal /// For test we could write 1.eur, is perfect for test especially This code looks much more like a natural language. Actually there are libraries that has a lot infix function especially for test Switch to slides Now there are a lot of util methods that we use a lot of times, for example in String in Kotlin you can find methods like isNotBlank isBlank etc, and in boolean, int, list, etc. on Kotlin from Java, It will be looked like a regular static method Ok, moving on listOf(BigDecimal.valueOf(1), BigDecimal.valueOf(100), BigDecimal.valueOf(10), BigDecimal.valueOf(10000)) fun main(args: Array<String>) { val monies = listOf( Money(BigDecimal.valueOf(1), "EUR"), Money(BigDecimal.valueOf(1), "EUR"), Money(BigDecimal.valueOf(1), "EUR") ) listOf(BigDecimal.valueOf(1), BigDecimal.valueOf(100), BigDecimal.valueOf(10), BigDecimal.valueOf(10000)) fun main(args: Array<String>) { val monies = listOf( Money(BigDecimal.valueOf(1), "EUR"), Money(BigDecimal.valueOf(1), "EUR"), Money(BigDecimal.valueOf(1), "EUR") ) val sum = monies.stream() .mapToBigDecimal { it.amount } .sum() listOf(BigDecimal.valueOf(10), BigDecimal.valueOf(10), BigDecimal.valueOf(10), BigDecimal.valueOf(1000), BigDecimal.valueOf(1)) listOf(10.b, 10.b, 10.b, 1000.b, 1.b) val money = 10 toMoney "EUR" val money2 = 10 toMoney "EUR" money isEqualsTo money2 } private infix fun Int.toMoney(s: String): Money { return Money(this.b, s) } private val Int.eur: Money get() { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } private val Int.c: BigDecimal get() { return BigDecimal.valueOf(this.toLong()) } private val Int.b: BigDecimal get() = BigDecimal.valueOf(this.toLong()) private fun <T> Stream<T>.mapToBigDecimal(mapper: (T) -> BigDecimal): BigDecimalStream { return BigDecimalStream() } class Money(var amount: BigDecimal, val currency: String) { infix fun isEqualsTo(money: Money) { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } }