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
  • b

    Bernhard

    12/10/2018, 11:40 PM
    I'm wondering if contracts would help to get rid of that !!:
    dtos.filter { it.field != null }
        .map { OtherDto(it.field!!, it.otherField, it.anotherField) }
    w
    g
    • 3
    • 3
  • m

    Marc Knaup

    12/11/2018, 8:46 AM
    inline fun test(vararg properties: Pair<String, Any?>) {
       //(uses pairs)
    }
    
    test(
       "a" to 1,
       "b" to 2,
       …
    )
    Can the compiler optimize away the
    Pair
    allocations and maybe even the boxing? if so, is
    inline
    needed for that to happen?
    s
    g
    • 3
    • 15
  • a

    Andrew Gazelka

    12/11/2018, 3:28 PM
    is there a good equivalent of a "multiset" in Kotlin? I don't care about order. I simply care about element count and I want to compare equality between to multisets.
    t
    s
    a
    • 4
    • 10
  • d

    Dias

    12/11/2018, 4:51 PM
    Hi, when exactly package level variable gets initialized? when it is imported like in python?
    d
    • 2
    • 6
  • g

    gcx11

    12/11/2018, 9:55 PM
    Hello, why this does not compile? Is it some bytecode limitation? It compiles fine if functions are declared inside a class.
    fun main() {
        fun foo() {
            bar()
        }
    
        fun bar() {
            println("Called")
        }
    
        foo()
    }
    d
    s
    • 3
    • 2
  • j

    jiangxingbing

    12/12/2018, 2:08 AM
    Hello everyone, I have a question about interoperability between Kotlin and Java. I have a Kotlin class
    A
    extend from a Java class
    Base
    which has a static function
    f()
    . When I called
    A.f()
    in a Kotlin file the IDE give an error ” Unresolved reference: f “. But when I called
    A.f()
    in a Java class, It works fine. I want to know the reason and maybe correct implementation. Thanks!
    g
    • 2
    • 1
  • r

    roberto

    12/12/2018, 2:54 AM
    Hello, I've a question about maps and potentially lambdas, I've a map mapping int to objects creation, something like this: val menuIdToItems: Map<Int, MyObject> by lazy { mapOf( menu1 to Item1.newInstance(), menu2 to Item2.newInstance(), menu3 to item3.newInstance(), ) It's working fine, BUT I just realised that when I evaluate menuIdToItems[menu1], I actually need a NEW INSTANCE every time I evaluate menuIdToItems[menu1]. Right now, If I evaluate menuIdToItems[menu1] two times, second time will return the same instance that I got the first time. Is there a way to do this using a map?
    g
    • 2
    • 10
  • l

    Lulu

    12/12/2018, 7:39 AM
    Good morning. Is there a channel for kotlinx.serialization?
    g
    • 2
    • 2
  • p

    Paul Woitaschek

    12/12/2018, 9:34 AM
    Is it possible to iterate on all kclass types of a sealed class? I use moshi and use https://github.com/square/moshi/blob/master/adapters/src/main/java/com/squareup/moshi/adapters/PolymorphicJsonAdapterFactory.java Therefore I need to registert all children of a sealed class and I want some compile time safety and want to make sure I handled all sub classes.
    d
    • 2
    • 2
  • l

    Louis

    12/12/2018, 10:46 AM
    Hello ! I would like to do something on a list, i think there is a function i don't know but i don't find it... Here is my code :
    val stringList = somethingList.map {
       it.str
    }
    
    if (stringList.isNotEmpty()) {
       doSomethingWithMyList(stringList)
    }
    And i would like to do something like that
    somethingList.map {
       it.str
    }.unknownOperation { // here i need help
       doSomethingWithMyList(it)
    }
    m
    g
    • 3
    • 6
  • a

    arve

    12/12/2018, 11:13 AM
    Hi. I'm implementing a toy ServiceLocator kind of thing. Is it possible to achieve something akin to this via the type system?
    fun registerService(interface: ???, impl: ???) { ... }
    
    registerService(UserInterface::class, UserService()) // ok
    registerService(CarInterface::class, CarService()) // ok
    registerService(ChairInterface::class, TableService()) // fail, because TableService does not implement ChairInterface
    d
    • 2
    • 3
  • j

    jkbbwr

    12/12/2018, 2:55 PM
    Can anyone suggest an alternative to ktor-client websockets? They seem fundimentally broken and unusable
    m
    s
    m
    • 4
    • 6
  • w

    wakingrufus

    12/12/2018, 2:56 PM
    Is there a way to get sealed class smart casting to work when filtering a collection on an
    is
    predicate and then doing operations on the subclass further down the chain?
    s
    m
    • 3
    • 11
  • t

    tKw

    12/12/2018, 3:38 PM
    Hello all! Has anyone had luck mocking Exposed using MockK?
    c
    m
    • 3
    • 7
  • d

    davidasync

    12/12/2018, 4:49 PM
    Hello, I got this error after try to run generated jar any idea ?
    ➜  life-drain git:(master) ✗ ./gradlew build && java -jar build/libs/life-drain-1.0-SNAPSHOT.jar
    w: /home/kotl/repo/watchanimeonline/life-drain/src/main/kotlin/com/life/drain/libs/GetMovieUrls.kt: (65, 33): Unnecessary non-null assertion (!!) on a non-null receiver of type List<String>
    
    BUILD SUCCESSFUL in 3s
    6 actionable tasks: 6 executed
    Error: A JNI error has occurred, please check your installation and try again
    Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/functions/Function1
    	at java.lang.Class.getDeclaredMethods0(Native Method)
    	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    	at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    	at java.lang.Class.getMethod0(Class.java:3018)
    	at java.lang.Class.getMethod(Class.java:1784)
    	at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
    Caused by: java.lang.ClassNotFoundException: kotlin.jvm.functions.Function1
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    	... 7 more
    m
    c
    +2
    • 5
    • 11
  • x

    xenoterracide

    12/12/2018, 6:42 PM
    https://kotlinlang.org/docs/reference/reflection.html but how do I search for a method name by annotation, and then exec said method? seems more like this documents method references than true reflection.
    a
    • 2
    • 11
  • n

    Nick Johnson

    12/12/2018, 8:06 PM
    @paulex use openjdk instead
    p
    • 2
    • 1
  • c

    crummy

    12/13/2018, 6:28 AM
    Maybe a basic question, but I want to filter a list, call a function with each matching element, then collate the results to a new list. Is there a more elegant way than this:
    val filtered = all.filter { it.foo }
       .map {
          callFunction(it)
          return it
       }.toList()
    g
    • 2
    • 16
  • d

    Davio

    12/13/2018, 7:34 AM
    Did you try using
    in T
    ?
    s
    s
    • 3
    • 2
  • j

    jonathan

    12/13/2018, 8:25 AM
    Kotlin doesn't have a notion of union types, so I imagine it would either smart cast it to the nearest superclass (probably
    Entity
    ), or not cast it at all.
    b
    • 2
    • 1
  • j

    jkbbwr

    12/13/2018, 10:42 AM
    Why have a holder, why not just have a sealed class
    m
    • 2
    • 1
  • m

    Marc Knaup

    12/13/2018, 3:21 PM
    Is there a way to use interface delegation and access the delegate without making it a constructor parameter? 🤔
    m
    • 2
    • 2
  • w

    wathek

    12/13/2018, 4:52 PM
    everytime I try to compile it says
    error: invalid method declaration; return type required
    s
    e
    • 3
    • 6
  • s

    samir

    12/13/2018, 5:21 PM
    Next Kotlin meetup in Paris if anyone is interested :) http://meetu.ps/e/G6sXz/vNnx2/d
    t
    l
    • 3
    • 2
  • x

    xenoterracide

    12/13/2018, 5:52 PM
    are their code quality tools that work with kotlin? checkstyle, spotbugs, and error prone are what I use with java.
    s
    m
    j
    • 4
    • 13
  • x

    xenoterracide

    12/13/2018, 10:54 PM
    does kotlin make use of jigsaw modules?
    g
    m
    • 3
    • 2
  • x

    xenoterracide

    12/14/2018, 6:48 AM
    what's the proper way to define a void fun
    j
    g
    • 3
    • 3
  • l

    lawlorslaw

    12/14/2018, 8:55 AM
    if i have a
    List<Tide>
    where a
    Tide
    has a field
    tide
    that is of type
    Float
    , what is the best way to sort by the
    tide
    field? I tried
    tides.sortedBy { it.tide }
    but it throws a ClassNotFoundException
    g
    • 2
    • 1
  • c

    cueball

    12/14/2018, 9:40 AM
    class RideException(private val errorCode: ErrorCode, t: Throwable) : Exception(t) {
    
        constructor(errorCode: ErrorCode) : super(errorCode.exceptionMessage)
    }
    getting error near
    super
    -> primary constructor expected
    g
    k
    • 3
    • 3
  • d

    Dominaezzz

    12/14/2018, 12:02 PM
    I have a list of
    class Node(val name: String, val parent: String?)
    , I want to find the last node in the list that is a child of a child of a child....... of the first element. How to do this without using `var`s?
    e
    • 2
    • 3
Powered by Linen
Title
d

Dominaezzz

12/14/2018, 12:02 PM
I have a list of
class Node(val name: String, val parent: String?)
, I want to find the last node in the list that is a child of a child of a child....... of the first element. How to do this without using `var`s?
e

Egor Trutenko

12/14/2018, 12:05 PM
Could you please clarify - you need the deepest element?
d

Dominaezzz

12/14/2018, 12:06 PM
Yes.
Such that every element before it in the list, is a parent of the next element.
View count: 5