Some features I used when converting from Java
view?.displayInvalidCardErrorMessage()if (view != null) {
view.hideProgressSpinner();
}Kotlin:
Java:
fun Check.getFirstOpenCreditCardPayment(): Optional<Payment> {
return Optional.fromNullable(payments.firstOrNull { payment ->
payment.paymentType == Payment.Type.CREDIT &&
!payment.isDeleted &&
payment.paymentStatus == Status.OPEN })
}private Predicate<Payment> isOpenCreditCard = payment -> {
return payment.paymentType == Payment.Type.CREDIT
&& !payment.isDeleted()
&& payment.paymentStatus == Status.OPEN;
};
private Optional<Payment> getFirstPayment(Check check, Predicate condition) {
Optional<ToastPosOrderPayment> result = FluentIterable.from(check.payments)
.filter(condition)
.first();
return result;
}
public Optional<Payment> getFirstOpenCreditCardPayment(Check check){
return getFirstPayment(check, isOpenCreditCard);
}FluentIterable:
Kotlin built in collections methods:
fun CardReaderService.canTakeEmvPayment(): Boolean {
return (canTakeQuickChipPayment() || canTakeFullEmvPayment())
} in KioskCardReaderServiceExtensionFunctions.kt
The fastest growing language in 2018
2.6x the number of github contributors
One of the most loved languages of 2018
5-10 years ahead of Java
Google recommends:
"If you're starting a new project, you should write it in Kotlin"
250-person R&D team
Tens of thousands of customers in the US
Processing billions in payments every year
July 2013: First live customer
April 2019: $250 million in Series E funding at $2.7 billion valuation
< 10% US POS market share so far
Lots more growth to come!
2018: Revenue up 148%
Kotlin can be compiled to any Java version bytecode
Kotlin can even be compiled to Javascript
Kotlin can even be compiled to native binaries for iOS, OSX, Windows, Linux etc.
Kotlin is a better language for the JVM than Java
Really easy to get up and running
Simpler language than Java
Much safer than Java
No more NullPointerExceptions!
Streamlines the handling of null values
Much more clean & concise than Java
100% Interoperable with Java
Kotlin & Java classes can live side by side
Writing Java in Kotlin
Which is fine
Gradually learn more idomatic Kotlin
Discover the std lib tools with autocomplete
val myString: String? = null
println(myString.isNullOrEmpty()) // prints true!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
)A series of exercises to get you familiar with the Kotlin syntax and features
The best way to learn all the language features
Written by Svetlana Isakova
Also wrote Kotlin in Action and Atomic Kotlin
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
Find a pair to work with!