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
announcements
  • g

    GarouDan

    04/19/2018, 9:56 PM
    well, I think for now jcenter is good to go. but my doubt is, can kotlin-stdlib be used with java 8, 10 for example?
    c
    • 2
    • 2
  • f

    Fleshgrinder

    04/20/2018, 8:49 AM
    Hey guys 🙂 I want to design a fluent interface but it seems as if the variance of Kotlin/JVM is not good enough for creating actual DRY code; or maybe I'm missing something?
    sealed class A {
        fun a() = apply { /* doSomething */ }
    }
    
    class B : A() {
        fun b() = apply { /* doSomething */ }
    }
    
    class C : A() {
        fun c() = apply { /* doSomething */ }
    }
    
    B().a().b() // cannot call b() now :(
    C().a().c() // cannot call c() now :(
    k
    • 2
    • 1
  • f

    fusdahl

    04/20/2018, 10:33 AM
    When using the operator overloaded
    /
    to divide big decimals the outcome is kind of unexpected:
    40.toBigDecimal() / 100.toBigDecimal()
    0
    40.toBigDecimal().divide(100.toBigDecimal())
    0.4
    This seems to be a result of
    /
    using the half even rounding mode. Does anyone know why this rounding mode was chosen?
    i
    • 2
    • 1
  • s

    Sergio Crespo Toubes

    04/20/2018, 10:49 AM
    Can i migrate a groovy android project to kotlin class by class? or i have to migrate all project to kotlin for compile? I am getting this error "Unresolved reference" trying to use a groovy class.
    m
    • 2
    • 1
  • a

    adam-mcneilly

    04/20/2018, 1:05 PM
    Sidebar, let's discuss in :thread-please:: If I'm initializing an empty list, is there a performance difference between
    emptyList()
    and
    ArrayList()
    ?
    j
    p
    +2
    • 5
    • 11
  • m

    Michael

    04/20/2018, 4:18 PM
    Is there a kotlin way to do a string to regex and have it be “Un-greedy” or “lazy”?
    j
    • 2
    • 4
  • a

    Andreas Sinz

    04/20/2018, 4:27 PM
    @Michael Regex in kotlin is the same as in java and sadly there is no non-greedy modifier in java, you need to use reluctant modifiers https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html
    m
    • 2
    • 2
  • r

    ribesg

    04/20/2018, 10:07 PM
    Why does this creates TONS of objects, and what should I do to prevent it?
    cache.entries.removeAll {
                val res = now - it.value.first > duration
                if (res) <http://log.info|log.info>("Removing value in cache $name for key ${it.key}")
                res
            }
    o
    • 2
    • 16
  • f

    Fuyang

    04/20/2018, 10:09 PM
    question: when using lambda on list such as
    list.map { process(it) }
    , how can I print out the progress? Using onEach and a counter outside?
    r
    • 2
    • 4
  • d

    Dexter

    04/21/2018, 1:07 AM
    Got it. Also what are the semantics if you trigger an exception in one of the deferred lambdas? I hope you would absorb the exception and execute all the lambdas. Also I would expect the deferred lambdas to be executed in LIFO order.
    g
    • 2
    • 1
  • a

    Andreas Sinz

    04/21/2018, 1:16 PM
    what library are you using?
    d
    • 2
    • 3
  • l

    lielran

    04/22/2018, 1:46 PM
    I tried to use
    com.github.johnrengelman.shadow
    but failed to provide the main-class via
    application
    block
    x
    p
    • 3
    • 18
  • j

    Juan

    04/22/2018, 7:35 PM
    What's wrong with
    if (list is ObservableList<Course>)
    ? it's displaying this error "Cannot check for instace of erased type: ObservableList<Course>"
    c
    c
    c
    • 4
    • 12
  • s

    sujin

    04/23/2018, 9:50 AM
    How to print query in
    Room
    ? Not the query written in dao but the query generated by room itself.
    :stackoverflow: 6
    a
    • 2
    • 1
  • p

    pankajrai

    04/23/2018, 12:02 PM
    Do creation of Singleton has been changed now? object MySingleton { val num:Int = 10 } No longer create a private constructor
    a
    p
    • 3
    • 8
  • d

    davidarteaga

    04/23/2018, 5:14 PM
    Hey guys. I am using coroutines to run several long tasks in parallel, and I would like to time each of the tasks, but considering only the time that the coroutine has actually been executed (that is, excluding the time it was suspended). I haven’t been able to find any info on this yet. Anyone have a suggestion?
    a
    p
    • 3
    • 8
  • w

    warriorprincess

    04/23/2018, 5:55 PM
    https://codeshare.io/2EbP7O
    a
    p
    • 3
    • 19
  • p

    pavel

    04/23/2018, 7:52 PM
    I would read
    foo.if { bar() }
    as return
    foo
    if
    bar()
    is true
    g
    a
    • 3
    • 5
  • g

    gabrielfv

    04/23/2018, 7:57 PM
    My use case is taking a long stream of functional-like calls. Instead of wrapping everything around an
    if
    or assigning it all to a variable, I just call it like that:
    data
        .filter { it.hasErrors }
        .map { it.error }
        .any { it is MyException }
        .then { /*Treat that exception*/ }
    a
    • 2
    • 1
  • z

    zpearce

    04/23/2018, 8:06 PM
    Not as pretty:
    data
        .filter { it.hasErrors }
        .map { it.error }
        .takeIf { it is MyException }
        ?.let { dealWith(it) }
    👍 2
    a
    • 2
    • 2
  • j

    John

    04/23/2018, 8:11 PM
    Just joined the group although still a beginner in kotlin
    a
    • 2
    • 2
  • k

    kschlesselmann

    04/24/2018, 6:02 AM
    Can I use `data class`es for JPA Entities having equals only on
    id
    and the other using
    val
    somehow? In order to generate
    equals()
    only of
    id
    it has to be the only argument in the primary constructor.
    @Entity
    data class Term(
            @Id
            val id: UUID,
    
            val name: String
    ) {
    
        val definition: Definition = Definition.DEFAULT
    
        constructor(id: UUID, name: String, definition: Definition) : this(id, name) {
            this.definition = definition
        }
    }
    I think I'd like to do someting like this …
    g
    • 2
    • 1
  • v

    v79

    04/24/2018, 8:44 AM
    Can I use a typealias to get around multiple constructors having the same parameter types? e.g.
    typealias Prefix = String; class Form(request: Request, prefix: String) { constructor(request: Request, postfix: String) : this(request, "") }
    (class abbreviated!)
    😢 1
    🇳🇴 3
    g
    u
    • 3
    • 10
  • y

    Yuriy Kulikov

    04/24/2018, 8:53 AM
    Hello everyone, our team is new to Kotlin (we are used to Java) and since we have to started to write new stuff in Kotlin, we cannot seem to agree on some best practices. Small stuff, mostly: 1. Where to put higher order functions and data classes - is it ok to write them directly in the same file or they have to be moved to a new file? Pro/contra? 2. Extension functions - is it ok to declare member extension functions in classes (i.e. extension functions which have access to class properties)? Or should be prefer higher end extension functions? Example: // declared in the class, access a class property private fun String.toTypeElement(): TypeElement { return processingEnv.elementUtils.getTypeElement(this) } -vs- // declared outside, class property must be passed as a parameter fun String.toTypeElement(processingEnv: ProcessingEnvironment): TypeElement { return processingEnv.elementUtils.getTypeElement(this) } Thanks a lot:-)
    e
    g
    +2
    • 5
    • 8
  • e

    edwardwongtl

    04/24/2018, 9:29 AM
    data class Response<T>(
      ...
      val data: List<T>
    }
    Has anyone using moshi to deal with this kind of object? I don't quite seems to find example for doing so..
    n
    e
    • 3
    • 37
  • a

    anli

    04/24/2018, 9:39 AM
    Hi! Home made (but not by me) annotation results in
    lateinit modifier is not allowed on extension properties
    error. How to resolve?
    g
    • 2
    • 5
  • c

    chirag

    04/24/2018, 10:12 AM
    data
                    .mapNotNull {
                        val type = it.asJsonObjectOrNull()?.get("type")?.asStringOrNull()
                        val events = it.asJsonObjectOrNull()?.get("events")?.asJsonArrayOrNull()
    
                        if (type != null && events != null)
                            type to events
                        else
                            null
    
                    }.toMap()
    a
    • 2
    • 1
  • c

    chirag

    04/24/2018, 10:13 AM
    due to if else statements
    g
    • 2
    • 3
  • e

    elect

    04/24/2018, 10:13 AM
    can you confirm me that an
    Array<Float>
    corresponds to
    Float[]
    on Java?
    g
    • 2
    • 2
  • k

    karelpeeters

    04/24/2018, 10:26 AM
    If you're calling it polymorphically it won't be inlined.
    e
    • 2
    • 5
Powered by Linen
Title
k

karelpeeters

04/24/2018, 10:26 AM
If you're calling it polymorphically it won't be inlined.
e

elect

04/24/2018, 10:26 AM
that is?
k

karelpeeters

04/24/2018, 10:27 AM
Let's say
class Child : Parent
and this function is in
Child
. If you have a
val child: Child
and a
val parent: Parent
only
child.foo()
will be inlined but
parent.foo()
won't.
Because it's not possible to inline, since there are multiple implementations and they're picked at runtime.
e

elect

04/24/2018, 10:29 AM
got it, thanks
it make sense though
View count: 1