kotlin-spring plugin for opening classes and methods > Official support from Spring Framework 5.0 plugins { // Kotlin Version 1.3.41 id "org.jetbrains.kotlin.plugin.spring" version "1.3.41" // Spring Boot Version 2.1.5.RELEASE id "org.springframework.boot" version "2.1.5.RELEASE" // Dependency Manager id "io.spring.dependency-management" version "1.0.8.RELEASE" } Kotlin
embodied string @Select(""" SELECT * FROM campaigns WHERE id = #{id} AND incentive_id = #{incentiveId} """) fun find(id: Long, incentiveId: Long): CampaignEntity? Kotlin
" campaigns " + " WHERE " + " id = #{id} " + " AND " + "incentive_id = #{incentiveId} ") public CampaignEntity find(long id, long incentiveId): Java OR Mapper @Select("SELECT * FROM campaigns WHERE id = #{id} AND incentive_id = #{incentiveId}") public CampaignEntity find(long id, long incentiveId): Java
Safe Compiler validates types and checks null while compiling > Few New Concepts The cherry pick from other languages Pragmatic Language [1] https://leanpub.com/effectivekotlin/
null JsonNode .Null key, value found val node = mapper.readTree(json) val value = node.get("scheme") if (value != null){ if (!value.isNull){ ... } } verbose Kotlin
val v: JsonNode? = this.get(name) return when { v == null || v.isNull -> null else -> v } } key isn’t found value is null null key, value found Kotlin extention
campaignUrl: String, val imageUrl: String? ) Nullable / Not Null fun getCampaigns(): List<CampaignProtocol>? = redisTemplate.opsForValue().get(CAMPAIGNS_KEY) Return value is Nullable Null Safety Infrastructure Web, Redis, DB… Domain Domain Model Use cases Business Logic Validation + Type
more and more in LINE > The Advantage of Kotlin Concise and null safety > Server-side Kotlin Pitfalls Be careful Platform Type when you use java library