Kotlin for android
-
Upload
shady-selim -
Category
Technology
-
view
135 -
download
0
Transcript of Kotlin for android
Speaker Bio
• Official Google Speaker
• GDG Helwan Founder & Leader
• Mobile & Web Evangelist
• Technology savvy
• Think tank, Father
• UI/UX freak
• Leader & Mentor
www.linkedin.com/in/shadyselim/
@dr_Shady_Selim
2
Why Should I care!!?
• Statically typed programming language targeting the JVM
• Support for functional and OO paradigms
• Pragmatic, safe, concise, great Java interop
• Free and open-source
• Drastically reduce the amount of boilerplate code
• Lambda expression
• Avoid entire classes of errors such as null pointer exceptions
• Java 9 is …
8
The Strengths of Kotlin
• Modeling the data of your application concisely and expressively
• Creating reusable abstractions using functional programming techniques
• Creating expressive domain-specific languages
• Java interop ensures that all existing Java frameworks can be used
• No rewrite required to start using Kotlin in existing codebase
• Existing investment is fully preserved
9
Java Model Example
10
public class Customer {
private String name;
private String email;
private String company;
public Customer(String name) {
this(name, "", "");
}
public Customer(String name, String email) {
this(name, email, "");
}
public Customer(String name, String email, String company) {
this.name = name;
this.email = email;
this.company = company;
}
Java Model Example, cont.
11
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
Java Model Example, cont.
12
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Customer customer = (Customer) o;
if (name != null ? !name.equals(customer.name) : customer.name != null) return false;
if (email != null ? !email.equals(customer.email) : customer.email != null) return false;
return company != null ? company.equals(customer.company) : customer.company == null;
}
Java Model Example, cont.
13
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (email != null ? email.hashCode() : 0);
result = 31 * result + (company != null ? company.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Customer{" +
"name='" + name + '\'' +
", email='" + email + '\'' +
", company='" + company + '\'' +
'}';
}
}
Kotlin Model Example, cont.
14
data class Customer(var name: String,
var email: String = "",
var company: String = "")
Resources
• https://kotlinlang.org/
• https://m.signalvnoise.com/kotlin-its-the-little-things-8c0f501bc6ea
• https://www.jetbrains.com/
• https://www.slideshare.net/intelliyole/kotlin-why-do-you-care
• https://github.com/ReactiveX/RxKotlin
• https://spring.io/blog/2016/02/15/developing-spring-boot-applications-with-kotlin
• https://www.slideshare.net/makingx/spring-kotlin
• https://kotlin.link/
19