9th July 2018
Much safer than Java
No more NullPointerExceptions!
Streamlines the handling of null values
More more clean & concise than Java
100% Interoperable with Java
Kotlin & Java classes can live side by side
~99% can be compiled to Java 6 bytecode
Can be compiled to Javascript
Can be compiled to native binaries for iOS, OSX, Windows, Linux etc.
public class Person {
private final String firstName;
private final String lastName;
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Person person = (Person) o;
if (firstName != null ? !firstName.equals(person.firstName) : person.firstName != null) {
return false;
}
return lastName != null ? lastName.equals(person.lastName) : person.lastName == null;
}
@Override
public int hashCode() {
int result = firstName != null ? firstName.hashCode() : 0;
result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Person{" +
"firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
'}';
}
}data class Person(
val firstName: String,
val lastName: String
)public class MainJava {
public static void main(String[] args) {
Person player1 = new Person("Bob", null);
Person player2 = new Person("Tomás", "Hanley");
.
.
.
.
if (player1.getLastName().equals(player2.getLastName())) {
System.out.println("Last names equal! 😁");
} else{
System.out.println("Last names not equal 😭");
}
}
}A series of exercises to get you familiar with the Kotlin Syntax
Highly recommend you use Intellij
Comes bundled with Kotlin & great tools
Install the EduTools plugin
Preferences -> Plugins -> Install Jetbrains plugins
Search EduTools, install & restart Intellij
Select Learner if prompted on restart
File > Browse courses and select Kotlin
Refresh your gradle dependencies
https://kotlinlang.org/
https://www.slideshare.net/intelliyole/kotlin-riviera-dev
https://speakerdeck.com/alexgherschon/introduction-to-kotlin