https://kotlinlang.org logo
Docs
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
getting-started
  • r

    Ruckus

    01/04/2019, 7:00 PM
    What would you expect to happen if you didn't? For example:
    open class Parent(val num: Int)
    class Child : Parent
    
    println(Child().num)  // What should this print?
    k
    • 2
    • 2
  • k

    karelpeeters

    01/04/2019, 7:09 PM
    start until start + count
    p
    • 2
    • 1
  • a

    aarjav

    01/05/2019, 8:14 PM
    Is there a java jni style interface for Kotlin jvm and native? Just curious
    d
    • 2
    • 3
  • p

    poohbar

    01/06/2019, 12:05 AM
    this might be just my ocd speaking but is no one bothered by the gap before
    .map
    ?
    return sequence {
        // some code
        yield(thing)
    }
        .map { it.something }
        .toList()
    Am i formatting it wrong? How would you format it?
    e
    • 2
    • 1
  • e

    Egor

    01/06/2019, 8:09 PM
    Can anybody explain this piece of code from one of the example in the "_The in Keyword_" section from the book " Atomic Kotlin "?
    fun main(args: Array<String>) {
      println("ab" in "aa".."az")
      println("ba" in "aa".."az")
    }
    
    /* Output:
    true
    false
    */
    I can understand that you can validate the range between 'a'..'z'. I'm just not quite able to grasp the idea of validating 'aa'..'az'
    s
    d
    +2
    • 5
    • 7
  • s

    serebit

    01/06/2019, 11:38 PM
    think of the strings as base-26 integers @Egor
    a
    s
    +2
    • 5
    • 44
  • r

    Romain

    01/07/2019, 9:19 AM
    Hello, I have a lateinit variable that is initialized in
    init()
    but when I call the function
    doSomething()
    I have the exception "lateinit property c has not been initialized". I don't really get why as it has been initialized before. This is on Android. Thank you
    -.kt
    t
    k
    • 3
    • 4
  • d

    dG

    01/07/2019, 4:39 PM
    I'm trying to use mockito_kotlin, but cannot figure out how to use the
    any
    (
    inline fun <reified T : Any> any()
    ). What would be appropriate syntax here, to include a class T?
    a
    p
    +2
    • 5
    • 7
  • m

    Matheus

    01/08/2019, 3:12 PM
    What would be an idiomatic way of only adding an item to a map if it's not null?
    val item1: String = ""
    val item2: String? = getItem2()
    
    val map = mapOf(1 to item1, 2 to item2) //only if item2 is not null
    d
    a
    • 3
    • 6
  • d

    dvlwj

    01/09/2019, 3:47 AM
    Guys, i write a code for a program that have money on it, i am using
    Match.ceil
    feature for this, to predict they payment the buyer gonna use. The problem is for use
    Match.ceil
    i need to have the number in
    float
    , but then i read this https://stackoverflow.com/a/3730040 , which is telling that a bad one to use
    float
    for financial purpose. What i need to do? My code is something like this :
    val a: Double = valueInput1.toDouble()
        val b: Double = 5000.toDouble()
        val c = Math.ceil(a/b)*5000
        println(c)
    s
    • 2
    • 16
  • a

    A Gamal

    01/09/2019, 10:24 AM
    Why is it not possible to have a custom getter on
    lateinit
    ? I use
    isInitialized
    everytime I access
    lateinit
    , so I wonder if I could optimize that and only do the check once. In case of a nullable type, I could do something like that.
    n
    p
    m
    • 4
    • 13
  • b

    bodiam

    01/09/2019, 12:41 PM
    Hi all. I'm looking into Kotlin + JPA, and most of the examples I've seen so far are using Kotlin Data classes. But while I (think I) understand data classes, I don't understand what the added benefit is in regards to JPA. Anyone suggestions?
    m
    t
    • 3
    • 4
  • p

    poohbar

    01/09/2019, 6:22 PM
    I need to call a private constructor of a nested class from a companion defined in the outer class.
    h
    a
    • 3
    • 2
  • p

    poohbar

    01/09/2019, 6:27 PM
    I need to prevent other classes from instantiating the
    Child
    a
    • 2
    • 1
  • o

    oday

    01/12/2019, 1:27 PM
    what's the syntax mean to inject there specifically
    s
    • 2
    • 1
  • m

    MichaelMalus

    01/13/2019, 12:21 AM
    Hola all. I'm trying to build a JsonObject from known data, by the following. And guesses why it's not working?
    val samplemessage = json {
        "decodes" to {
            "ref" to 43989
            "vrm" to "AV11LPR"
            "frameID" to 12029991
            "spacedVRM" to "AV11 LPR"
            "seenCount" to 18
            "cameraName" to "Test_MAV_IQ"
            "decodeID" to 44606
            "repeatedPlate" to false
            "timeStamp" to
                    {"Time" to 1473670749
                        "ms" to 64
                        "LocalTime" to 1473677949}
            "timeSync" to
                    {"timeMode" to 0
                        "lastSyncTime" to 1473062065
                        "lastSyncSource" to "SNTP"
                        "lastSyncInfo" to "192.53.103.108"}
            "direction" to 126
            "motion" to "towards"
            "frameTimeRef" to 606284767
        }
    }
    s
    • 2
    • 11
  • a

    aarjav

    01/13/2019, 5:02 PM
    Is there a multiplatform cache library like caffeine or guava's cache on the jvm?
    d
    p
    • 3
    • 3
  • g

    gaspard

    01/13/2019, 9:23 PM
    Ok, Kotlin is a well done language, each problem as an easy solution! so I just added in my class
    constructor(param1: String, param2 : string) : this(param1, param2 = "default value")
    n
    • 2
    • 1
  • k

    Kevin

    01/16/2019, 4:01 AM
    What's the best choice of data structure?
    a
    • 2
    • 3
  • e

    edwardwongtl

    01/16/2019, 6:01 AM
    A simple mutable list?
    ☝️ 1
    a
    • 2
    • 1
  • o

    oday

    01/16/2019, 2:52 PM
    s/working/initialized
    s
    • 2
    • 6
  • k

    Kevin

    01/16/2019, 6:53 PM
    Is there a way to do that easily?
    🇳🇴 1
    m
    • 2
    • 1
  • n

    nerdstone

    01/16/2019, 7:59 PM
    Hi, am trying to understand
    reified
    modifier but don't seem to be getting it well could someone please explain it or rather send a link with its usage? That will be helpful
    r
    n
    c
    • 4
    • 6
  • s

    Shawn

    01/16/2019, 9:39 PM
    is the file called
    Main.kt
    ?
    t
    • 2
    • 5
  • f

    febs

    01/16/2019, 9:49 PM
    the error is "Error:(20, 35) Kotlin: Type mismatch: inferred type is (Int) -> Int but ((Int) -> CharSequence)? was expected". Should I explicitly convert that to a CharSequence? Why? 🤔
    z
    t
    +2
    • 5
    • 9
  • b

    Bernhard

    01/17/2019, 10:21 AM
    hi, is "if (value in set)" valid?
    d
    r
    • 3
    • 4
  • u

    ursus

    01/17/2019, 5:22 PM
    Why cant I format my bitewise ors to be on new lines?
    bytes[0].toInt() shl 24 or (bytes[1].toInt() and 0xFF shl 16) or (bytes[2].toInt() and 0xFF shl 8) or (bytes[3].toInt() and 0xFF);
    any sane person would write it alteast as
    fun byteArrayToInt(bytes: ByteArray): Int {
                return bytes[0].toInt() shl 24
                or (bytes[1].toInt() and 0xFF shl 16)
                or (bytes[2].toInt() and 0xFF shl 8) 
                or (bytes[3].toInt() and 0xFF);
    }
    s
    • 2
    • 5
  • a

    amiracam

    01/17/2019, 11:12 PM
    hi newbie, is there a maven coordinate that I can run from a build.gradle ? I would be building TornadaFX apps from IDEA , thanks
    h
    • 2
    • 3
  • t

    Tsvetozar Bonev

    01/18/2019, 10:54 AM
    How do I run three suspend functions and await their execution at the same time?
    a
    • 2
    • 2
  • u

    Uzi Landsmann

    01/18/2019, 12:22 PM
    I have a multiline yaml string that I’d like to use in a program. The problem is that it contains dollar signs and quotes, which if I understand correctly cannot be escaped in a multiline string. Is my only option to concatenate many single line strings? Or is there another way?
    k
    a
    • 3
    • 10
Powered by Linen
Title
u

Uzi Landsmann

01/18/2019, 12:22 PM
I have a multiline yaml string that I’d like to use in a program. The problem is that it contains dollar signs and quotes, which if I understand correctly cannot be escaped in a multiline string. Is my only option to concatenate many single line strings? Or is there another way?
k

karelpeeters

01/18/2019, 12:23 PM
You mean something like this? https://pl.kotl.in/SyzLHBJXV
You don't even need to escape them.
u

Uzi Landsmann

01/18/2019, 12:27 PM
Unfortunately they look like like this: “”" “${somthing}” “”"
a

Alowaniak

01/18/2019, 12:27 PM
If there's valid identifier characters right after the dollar sign it'll say it's an unresolved reference though, in that case you could do
${'$'}foo
u

Uzi Landsmann

01/18/2019, 12:28 PM
No it’s not 😞 it’s identifiers for the other system that receives that string
sort of a template
a

Alowaniak

01/18/2019, 12:29 PM
yea so you could do
"""
“${'$'}{somthing}”
"""
u

Uzi Landsmann

01/18/2019, 12:29 PM
Ok thanks, I’ll try it out
k

karelpeeters

01/18/2019, 12:29 PM
Wow that is surprising behavior.
u

Uzi Landsmann

01/18/2019, 12:56 PM
Thanks! It worked. But the way Intellij pastes the yaml is really strange. It adds the
{'$'}
in the wrong place and omits them where needed. But I guess it’s a question for another channel. Thanks again!
View count: 4