Share
Embed
Transcript
40 slides
-
Ѫᖒ๖ (Moyuru Aizawa) - Kotlin engineer at CyberAgent, Inc. -
FRESH! lvla0805 MoyuruAizawa -
public final class Person { @NotNull private final String firstName;
@NotNull private final String lastName; … @NotNull public final String getFirstName() { return this.firstName; } @NotNull public final String getLastName() { return this.lastName; } } Backing Fields and Accessors -
public final class Person { @NotNull private final String firstName;
@NotNull private final String lastName; … @NotNull public final String getFirstName() { return this.firstName; } @NotNull public final String getLastName() { return this.lastName; } } Backing Fields -
public final class Person { @NotNull private final String firstName;
@NotNull private final String lastName; … @NotNull public final String getFirstName() { return this.firstName; } @NotNull public final String getLastName() { return this.lastName; } } Accessors -
public final class Person { @NotNull private final String firstName;
@NotNull private final String lastName; … @NotNull public final String getFirstName() { return this.firstName; } @NotNull public final String getLastName() { return this.lastName; } } Backing Fields -
class Person { val firstName: String val lastName: String val
fullName get() = "$firstName $lastName" … } Declare custom accessors -
class Person { val firstName: String val lastName: String val
fullName get() = "$firstName $lastName" … } Declare custom accessors -
class Person { val firstName: String val lastName: String val
fullName get() = "$firstName $lastName" … } Declare custom accessors -
class Person { val firstName: String val lastName: String val
fullName get() = "$firstName $lastName" … } person.fullName Declare custom accessors -
public final class Person { @NotNull private final String firstName;
@NotNull private final String lastName; … @NotNull public final String getFirstName() { return this.firstName; } @NotNull public final String getLastName() { return this.lastName; } @NotNull public final String getFullName() { return this.firstName + " " + this.lastName; } } Declare custom accessors -
class Person { val firstName: String val lastName: String val
fullName get() = "$firstName $lastName" var age: Int set(value) { require(value >= 0) field = value } … } Declare custom accessors -
class Person { val firstName: String val lastName: String val
fullName get() = "$firstName $lastName" var age: Int set(value) { require(value >= 0) field = value } … } Declare custom accessors -
class Person { val firstName: String val lastName: String val
fullName get() = "$firstName $lastName" var age: Int set(value) { require(value >= 0) field = value } … } Declare custom accessors -
class Person { val firstName: String val lastName: String val
fullName get() = "$firstName $lastName" var age: Int set(value) { require(value >= 0) field = value } … } Declare custom accessors -
class Person { val firstName: String val lastName: String val
fullName get() = "$firstName $lastName" var age: Int set(value) { require(value >= 0) age = value } … } Declare custom accessors Stack Overflow -
class Person { val firstName: String val lastName: String val
fullName get() = "$firstName $lastName" var age: Int set(value) { require(value >= 0) field = value } … } person.age = 26 Declare custom accessors -
public final class Person { … private int age; …
public final int getAge() { return this.age; } public final void setAge(int value) { required(value) this.age = value; } } Declare custom accessors -
public final class Person { … private int age; …
public final int getAge() { return this.age; } public final void setAge(int value) { required(value) this.age = value; } } Declare custom accessors -
public final class Person { … private int age; …
public final int getAge() { return this.age; } public final void setAge(int value) { required(value) this.age = value; } } Declare custom accessors -
class NoBackingField { val property get() = "property" } No
Backing Fields -
public final class NoBackingField { @NotNull public final String getProperty()
{ return "property"; } } No Backing Fields -
interface User { val id: Long val name: String }
data class Follower(override val id: Long, override val name: String): User data class Me(override val id: Long, override val name: String, val email: String): User Interface can have Properties without Backing Fields -
interface User { val id: Long val name: String }
data class Follower(override val id: Long, override val name: String): User data class Me(override val id: Long, override val name: String, val email: String): User Interface can have Properties without Backing Fields -
interface User { val id: Long val name: String }
data class Follower(override val id: Long, override val name: String): User data class Me(override val id: Long, override val name: String, val email: String): User Interface can have Properties without Backing Fields -
val View.isVisible get() = visibility == View.VISIBLE val Activity.applicationComponent get()
= (application as CustomApplication).component Extend a class with new Properties without Backing Fields -
val View.isVisible get() = visibility == View.VISIBLE val Activity.applicationComponent get()
= (application as CustomApplication).component Extend a class with new Properties without Backing Fields -
val View.isVisible get() = visibility == View.VISIBLE val Activity.applicationComponent get()
= (application as CustomApplication).component Extend a class with new Properties without Backing Fields -
‣ Kotiln generates Backing Fields and Accessors ‣ You can
declare custom Accessors ‣ Interface can have properties without Backing Fields ‣ You can extend a class with new Properties without Backing Fields