Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Features of Kotlin I find exciting

2.739 Aufrufe

Veröffentlicht am

This short talk covers a few awesome things in Kotlin which make the language a lot more enjoyable.

Veröffentlicht in: Technologie
  • Als Erste(r) kommentieren

  • Gehören Sie zu den Ersten, denen das gefällt!

Features of Kotlin I find exciting

  1. 1. July 2018 Robert MacLean @rmaclean
  2. 2. 3 Robert MacLean @rmaclean SADEV.co.za
  3. 3. 4 Basic Pascal Delphi PHP Perl C# JavaScript TypeScript Java Kotlin
  4. 4. C# 5 Kotlin var name = ""; ... if (name != null) { } var member = existing ?? new Person(); var name = "" name = null // NOPE! var name : String? = "" var member = existing ?: Person()
  5. 5. C# 6 Kotlin var person = new Person(); ... if (person?.name != null) { } var person? = Person() ... if (person?.name != null) { } var s : String? = null println(s.length) // won’t compile println(s?.length) // null println(s!!.length) // NPE
  6. 6. JavaScript 7 Kotlin let numbers = [1, 5, 6, 7, 8]; let evens = numbers .filter(num => num % 2 === 0); val numbers = listOf(1, 5, 6, 7, 8) var evens = numbers .filter({ num -> num % 2 == 0 }) evens = numbers.filter({ it % 2 == 0 })
  7. 7. Java 8 Kotlin foo.is(bar) public void should_have_visible_logout() { } foo.`is`(bar) fun `should have visible logout`() { }
  8. 8. C# 9 Kotlin throw new Exception(); // compiler will tell you this won’t execute void start() { while (true) { ... } } start(); // compiler totally happy fun start():Nothing { while (true) { ... } } start() // compiler will tell you this won’t execute onwards!
  9. 9. Java 10 Kotlin public class Person { private String name; private int age = 0; public Person(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; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Person person = (Person) o; if (name != null ? !name.equals(person.name) : person.name != null) return false; if (age != 0 ? age != person.age : person.age != 0) return false; } @Override public int hashCode() {
  10. 10. public class Person { private String name; private int age = 0; public Person(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; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Person person = (Person) o; if (name != null ? !name.equals(person.name) : person.name != null) return false; if (age != 0 ? age != person.age : person.age != 0) return false; } @Override public int hashCode() { int result = name != null ? name.hashCode() : 0; result = 31 * result + age; return result; } @Override public String toString() { return "Person{" + "name='" + name + ''' + ", age='" + age + ''' + '}'; } }
  11. 11. C# 12 Kotlin class Person { public int Age {get; set;} public string Name {get; set;} public Person(int Age, string Name){ this.Age = Age; this.Name = Name; } }
  12. 12. Java 13 Kotlin public class Person { private String name; private int age = 0; public Person(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; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Person person = (Person) o; if (name != null ? !name.equals(person.name) : person.name != null) return false; if (age != 0 ? age != person.age : person.age != 0) return false; } @Override public int hashCode() { data class User(val name: String, val age: Int)
  13. 13. 14 Kotlin 101 29 August CodeBridge in Newlands http://bit.ly/kotlin101
  14. 14. 15 ExpertDrinks 2 August http://bit.ly/expertdrinks
  15. 15. Robert MacLean Twitter @rmaclean Web sadev.co.za 16

×