https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
announcements
  • r

    rrader

    01/31/2018, 3:09 PM
    kotlin-test-junit is not using junit 5?
    🇳🇴 2
    h
    • 2
    • 1
  • j

    jrtapsell

    01/31/2018, 4:52 PM
    e.g. Having a class which represents a list, (but doesn't implement list), and allowing the methods defined for lists to be usable on it?
    g
    • 2
    • 1
  • s

    Shawn

    01/31/2018, 6:16 PM
    you think we’ll ever get runnable Kotlin scratch files?
    a
    p
    +3
    • 6
    • 25
  • g

    gildor

    02/01/2018, 8:41 AM
    Kotlin Team works on feature called Contracts, that will allow such smart cast
    🆒 2
    e
    r
    • 3
    • 4
  • n

    nfrankel

    02/01/2018, 8:42 AM
    something like that?
    require(geometry is LineString) { "Wrong geometry type in string" }
    val line = geometry as LineString
    return line
    n
    • 2
    • 1
  • g

    gildor

    02/01/2018, 8:44 AM
    also you can use something like:
    fun String.toGeoLineString(): LineString {
       val geometry = readGeometryFromString(this)
       return requireNotNull(geometry as? LineString)
    }
    👍 1
    n
    • 2
    • 1
  • r

    rCorbellini

    02/01/2018, 9:38 AM
    Is it possible to develop for IOS with kotlin? Which IDE does Kotlin support for iOS?
    g
    • 2
    • 2
  • a

    aeruhxi

    02/01/2018, 10:37 AM
    Is it not possible to use a class' non-static function as a first class function?
    a
    • 2
    • 1
  • j

    jakub.dyszkiewicz

    02/01/2018, 10:41 AM
    Hi, why calling
    thenApply
    like this is possible
    CompletableFuture.completedFuture("x").thenApply { it }
    but second version with executor
    CompletableFuture.completedFuture("x").thenApply({ it }, Executors.newCachedThreadPool())
    throws compilation error and I have to do something like this
    CompletableFuture.completedFuture("x").thenApply(java.util.Function<String, String> { it }, Executors.newCachedThreadPool())
    l
    m
    • 3
    • 5
  • f

    fmcauley

    02/01/2018, 4:30 PM
    Any suggestions for where one could locate Kotlin jobs or job listings?
    m
    • 2
    • 2
  • k

    kevinmost

    02/01/2018, 6:02 PM
    .partition { ... }.let { (first, second) -> first + second }
    should work?
    👍 1
    j
    • 2
    • 1
  • k

    kevinmost

    02/01/2018, 7:29 PM
    and that
    in
    keyword can be used in a
    when
    for any
    operator fun contains
    , whether it's defined as
    String.contains
    ,
    List.contains
    , your own custom type's
    contains
    function, etc
    a
    • 2
    • 4
  • c

    christoph.pickl

    02/02/2018, 5:19 AM
    hi guys, yesterday i was asked an interesting question: how to deal with multiple optional values. should we go for simple null checks via if, or can we do it via a more sophisticated approach using something like let. given the following in an external module (to make it even harder to disable smart casting):
    data class Person(
            val name: String?,
            val age: Int?
    )
    fun moduleExternal() = Person("", 1)
    and a target function with a signature of:
    fun safeCall(x1: String, x2: Int) {}
    the following WON'T compile due to not being able to smart cast external module's properties:
    fun solution_no_smartcasts() {
        val person = moduleExternal()
        if (person.name != null && person.age != null) {
            safeCall(person.name, person.age) // ERROR!
        }
    }
    in order to get rid of the smart cast problem first, i came up with the following idea of destructuring:
    fun solution_destructure() {
        val (name, age) = moduleExternal()
        if (name != null && age != null) {
            safeCall(name, age)
        }
    }
    ok, but how about that "low level" if? apple's swift would solve it this way:
    if let name = person.name as? String, let age = person.age as? Int {
        // name and age are non-optional in here
    }
    so i thought about an extended if which "kind of" solves it:
    fun <T1, T2> ifNotNull(x1: T1?, x2: T2?, action: (T1, T2) -> Unit) {
        if (x1 != null && x2 != null) {
            action(x1, x2)
        }
    }
    
    fun solution_kotlin_lets() {
        val person = moduleExternal()
        ifNotNull(person.name, person.age) { name, age ->
            safeCall(name, age)
        }
    }
    what are your thoughts on this topic?
    d
    g
    u
    • 4
    • 6
  • g

    gildor

    02/02/2018, 9:28 AM
    @oleksiyp We just started to use Mockk in one of our modules to test it. API is really good, but I see problem that I don’t see stacktrace of undesirable call of some method on verify fail. Should I create feature request?
    o
    • 2
    • 3
  • p

    peasee

    02/02/2018, 11:50 AM
    Hi, just wanted to quickly ask if anyone here uses Hawk https://github.com/orhanobut/hawk for encrypting user credentials, or if I should use another library or just do it manually with key store.
    c
    • 2
    • 1
  • k

    karelpeeters

    02/02/2018, 7:44 PM
    Where did you get the
    scrollWindow
    value from? @elect
    e
    • 2
    • 2
  • a

    Athul Antony

    02/03/2018, 12:51 PM
    http://www.techeos.com/posts/android-kotlin-tricks.html
    k
    • 2
    • 1
  • j

    jrtapsell

    02/03/2018, 1:50 PM
    Could someone explain why
    org.jetbrains.kotlin:kotlin-stdlib-jre8
    has use for AutoCloseable, but
    org.jetbrains.kotlin:kotlin-stdlib-jdk8
    doesn't?
    c
    • 2
    • 1
  • s

    sxtanna

    02/03/2018, 5:44 PM
    Is there any particular reason there is no
    toMap()
    function available as an extension on a collection of
    Map.Entry<K, V>
    ?
    a
    o
    • 3
    • 3
  • s

    Shawn

    02/04/2018, 9:12 PM
    if you have a
    List<Int>
    and you just want the unique values, use
    .toSet()
    since sets don’t allow duplicate values
    k
    • 2
    • 1
  • t

    Tim

    02/04/2018, 10:20 PM
    i try to build "kotlin-web-demo" but get a lot if errors like "com.intellij.lang.java not found" on the current master. i am new to java / kotlin but shouldn't "./gradlew build" just works?
    a
    y
    • 3
    • 3
  • j

    jamie-purchase

    02/05/2018, 1:59 PM
    i'm probably doing something very dumb here (trying to match a literal dollar followed by chars in a string)...
    println("Hello \$name".contains(Regex("[a-zA-Z0-9]+"))) // true
    println("Hello \$name".contains(Regex("\$[a-zA-Z0-9]+"))) // false
    have to escape the dollar in the string literal or Kotlin will treat it as a reference and have to escape the dollar in the pattern or that means end of string
    s
    n
    • 3
    • 3
  • r

    Ronnie Magatti

    02/05/2018, 2:20 PM
    Is kotlinlang.org's CSS not loading for you guys too?
    z
    • 2
    • 3
  • e

    edwardwongtl

    02/05/2018, 2:35 PM
    Now that I think about it, top level function should make more sense when you do pure FP in Kotlin
    z
    • 2
    • 4
  • e

    Eivind

    02/05/2018, 3:05 PM
    Hi, I have some question about
    io.ktor.client.HttpClient
    and how to handle different return codes 400. Having trouble finding documentation and good examples. Just starting out whit kotlin as well.
    a
    • 2
    • 2
  • k

    kevinmost

    02/05/2018, 9:33 PM
    https://kotlinlang.org/docs/reference/properties.html#backing-fields
    k
    i
    • 3
    • 3
  • u

    user

    02/06/2018, 3:01 PM
    message has been deleted
    p
    • 1
    • 1
  • k

    karelpeeters

    02/06/2018, 3:09 PM
    How would the build cache work in practise over multiple machines?
    g
    • 2
    • 1
  • b

    bj0

    02/06/2018, 10:20 PM
    I have a
    data class
    that has a parameter
    metadata: List<Item>
    , and I'm creating it from a nullable with:
    metadata?.map { Item(it.key, it.value) } ?: listOf()
    . Which is compiling fine, but when metadata is null I'm getting:
    java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull
    a
    a
    • 3
    • 4
  • r

    roamingthings

    02/07/2018, 5:15 AM
    I’m looking for some kind of best practice how to model (bidirectional) JPA relations in Kotlin. I came up with the following solution but I’m not sure about the pros/cons. Especially when it comes to the mutability of the properties. Any suggestions?
    @Entity
    @Cacheable(false)
    data class Person(
            @Id @GeneratedValue
            val id: Long? = null,
    
            @NotBlank
            val name: String
    ) {
        @OneToMany(mappedBy = "person", cascade = [(CascadeType.ALL)])
        var addresses: MutableSet<Address> = HashSet()
    }
    
    @Entity
    @Cacheable(false)
    data class Address(
            @Id @GeneratedValue
            val id: Long? = null,
    
            @NotBlank val address: String
    ) {
        constructor(address: String, person: Person): this(address = address) {
            this.person = person
        }
    
        @NotNull
        @ManyToOne(optional = false)
        lateinit var person: Person
    }
    d
    • 2
    • 2
Powered by Linen
Title
r

roamingthings

02/07/2018, 5:15 AM
I’m looking for some kind of best practice how to model (bidirectional) JPA relations in Kotlin. I came up with the following solution but I’m not sure about the pros/cons. Especially when it comes to the mutability of the properties. Any suggestions?
@Entity
@Cacheable(false)
data class Person(
        @Id @GeneratedValue
        val id: Long? = null,

        @NotBlank
        val name: String
) {
    @OneToMany(mappedBy = "person", cascade = [(CascadeType.ALL)])
    var addresses: MutableSet<Address> = HashSet()
}

@Entity
@Cacheable(false)
data class Address(
        @Id @GeneratedValue
        val id: Long? = null,

        @NotBlank val address: String
) {
    constructor(address: String, person: Person): this(address = address) {
        this.person = person
    }

    @NotNull
    @ManyToOne(optional = false)
    lateinit var person: Person
}
d

dmulligan

02/14/2018, 5:39 PM
I have come across the same issue and never found a great solution. But what I have used init on the Person class to set the person on each item within the address list as follows.
init { addresses.forEach { it.person = this } }
View count: 2