
@ptyeen@mastodon.social Android & iOS app developer. Bug producer. Made a simple Twitter client: Depth
- Tweets21.7K
- Following272
- Followers625
- Likes32

ALT Did you know? You can create an "invoke" extension function on a companion object in Kotlin. This can keep your classes decoupled while still looking like a constructor. // Completely decoupled from UserRecord: class User(val name: String, val dateOfBirth: OffsetDateTime) { companion object } // Constructs a User from a UserRecord: operator fun User.Companion.invoke(record: UserRecord) = User( name = "${record.firstName} ${record.lastName}", dateOfBirth = OffsetDateTime.parse(record.dateOfBirth) ) // Invoke it like a constructor! val record: UserRecord = fetchFromSdk(userId = "USER_ID_12345") val user: User = User(record)






























