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
getting-started
  • k

    karelpeeters

    02/23/2019, 8:22 AM
    Yes, as described here: https://kotlinlang.org/docs/reference/operator-overloading.html#assignments
    h
    • 2
    • 1
  • o

    oday

    02/23/2019, 6:42 PM
    how do I sort a collection by several properties but preserving the sort as i go
    d
    i
    k
    • 4
    • 7
  • s

    Slava Glushenkov

    02/24/2019, 7:12 AM
    How do I sort ArrayList<Something> instead of theArrayList.sortBy{ it.foo} to avoid ConcurrentModificationException? CopyOnWriteArrayList?
    k
    • 2
    • 1
  • p

    Paul N

    02/24/2019, 5:09 PM
    If I have a class called
    Colour(val red:Double, val green: Double, val Blue: Double)
    what's the best way of defining some pre-defined colours, e.g. White being
    Colour(1.0,1.0,1.0)
    ?
    d
    d
    • 3
    • 3
  • k

    karelpeeters

    02/24/2019, 5:11 PM
    Probably the companion object:
    class Colour(...) {
        companion object {
            val White = Colour (1.0, 1.0, 1.0)
            ....
        }
    }
    Used like
    Colour.White
    .
    ➕ 6
    p
    i
    • 3
    • 2
  • n

    Neron.L

    02/27/2019, 9:34 AM
    Hi guys, I want know if there is a document about the Kotlin’s project structure and what the projects do? thanks
    k
    • 2
    • 1
  • h

    halirutan

    02/27/2019, 9:46 AM
    If have a string and a number of character ranges and I want to replace each range with inside the string with a different one which doesn't have the same length. So, e.g. if I have "Carla and Bob went to school" and I want to replace the ranges of the names with e.g.
    <name>Carla</name>
    to finally get "<name>Carla</name> and <name>Bob</name> went to school". Is there an easy way in Kotlin to achieve this without tracking the lengths that I have already inserted?
    d
    p
    • 3
    • 5
  • f

    Frido

    02/27/2019, 10:43 AM
    Hi guys, I have a question regarding properties vs parameters in Kotlin. I use KDoc and have something like this:
    /**
     * @property name ...
     */
    class Person(private val name: String)
    KDoc doesn't generate this. Only if I change property to param. Reading the linked SO thread it appears to actually be a property though. Can someone clarify please? https://stackoverflow.com/questions/45032436/what-is-the-difference-between-properties-and-parameters-in-kotlin
    h
    • 2
    • 4
  • p

    ptheocharis

    02/27/2019, 5:49 PM
    Moreover, if I make the fields non-nullable like this:
    data class GreetingDto(
      val greeting: String,
      val name: String
    )
    then I get another error:
    groovy.lang.GroovyRuntimeException: Could not find matching constructor for: app.greeting.GreetingDto(LinkedHashMap)
    j
    t
    • 3
    • 3
  • m

    Mark

    02/28/2019, 8:35 AM
    Suppose I have a kotlin interface with
    var background: Drawable
    and I want to create a Kotlin class implementing this interface and extending a java class that already defines
    setBackground(Drawable)
    and
    Drawable getBackground()
    . In Java, I don't need to do anything because the new subclass automatically implements these interface methods. In Kotlin, I get a compile error that the new subclass does not implement those interface methods. How to achieve this?
    d
    • 2
    • 8
  • k

    Kenneth

    02/28/2019, 12:33 PM
    Is it possible to write a Kotlin extension function that uses an autowired Spring bean?
    d
    • 2
    • 2
  • u

    Uraniam9

    02/28/2019, 3:52 PM
    Where is the best place to report compile errors and get answers instantly?
    k
    r
    +2
    • 5
    • 4
  • j

    Joe Bradshaw

    02/28/2019, 7:50 PM
    Hello. Is there a book or resource people would recommend for learning kotlin for more server programming than android?
    c
    h
    • 3
    • 5
  • o

    oday

    03/01/2019, 9:25 AM
    lucky
    t
    • 2
    • 1
  • t

    thanksforallthefish

    03/01/2019, 9:34 AM
    maybe worth knowing, I am on kotlin
    1.3.21
    and the base classes are from spring (maybe I can post in spring channel as well, but this seems more generally related to kotlin, spring is relevant only because I have no influence on how
    enhance
    is called, it has to accept `null`s)
    a
    r
    h
    • 4
    • 19
  • z

    zucen.co

    03/01/2019, 10:14 AM
    Hi, why does not work this?
    val pair = Pair(1,"xxx")
    map.put(*pair)
    w
    o
    • 3
    • 6
  • k

    KÖB

    03/01/2019, 9:05 PM
    Hi ! I'm just a Kotlin begginner (and Already addicted), Do you know if there's projects to participate in order to improve my skills ?
    c
    • 2
    • 2
  • s

    scottiedog45

    03/02/2019, 5:40 PM
    Hi everyone - is Anko a given for most android projects? I’m a beginner and don’t like being too abstracted from what’s going on. But if it’s part of the canon for android development then I think it would be fine to use.
    k
    a
    d
    • 4
    • 3
  • o

    Olav Hermansen

    03/03/2019, 8:14 AM
    Hello! I have a stream of items much like this:
    items.stream().filter { it.someStuff.equals(search) }.findFirst().orElseThrow( *insert exception* )
    I tried to put UnsupportedOperationException() but get problem with ExceptionSupplier. How should I do this?
    t
    m
    • 3
    • 4
  • m

    Mark McPartland

    03/03/2019, 11:44 AM
    Hi all, just get started with Kotlin. Have started my first super simple Kotlin Android app and looking for simplest way can send tweets to twitter from it. Google search hasn't helped so far, so does anyone know a good place to get some good info on doing this? cheers
    k
    • 2
    • 4
  • o

    oday

    03/03/2019, 8:32 PM
    i want to filter the list
    n
    • 2
    • 3
  • r

    Ruckus

    03/03/2019, 9:57 PM
    Currently it's implemented as
    public inline fun <K, V> MutableMap<K, V>.getOrPut(key: K, defaultValue: () -> V): V {
        val value = get(key)
        return if (value == null) {
            val answer = defaultValue()
            put(key, answer)
            answer
        } else {
            value
        }
    }
    but it seems to me (based on the kdoc) that is should be more like
    public inline fun <K, V> MutableMap<K, V>.getOrPut(key: K, defaultValue: () -> V): V {
        return if (contains(key)) {
            getValue(key)
        } else {
            val answer = defaultValue()
            put(key, answer)
            answer
        }
    }
    d
    i
    • 3
    • 4
  • o

    oday

    03/04/2019, 3:55 PM
    I want to filter the list for carMakes that have a constraint on the
    name
    field, then reconstruct this sortedmap agian
    p
    k
    • 3
    • 51
  • b

    bjonnh

    03/04/2019, 6:54 PM
    how can I do a sealed class that contains a data class and a String (that's for a Json file where I can have either of these two)
    r
    k
    s
    • 4
    • 19
  • s

    Scott White

    03/04/2019, 9:32 PM
    .iml files are getting really messed up in our Kotlin IntelliJ projects, any advice on that?
    d
    • 2
    • 4
  • d

    davec

    03/05/2019, 12:56 AM
    Sure, that's better, thanks. Interesting that
    ("a".."z").map{ it }
    doesn't work (compiler error), can't map a String range.
    i
    • 2
    • 1
  • v

    voddan

    03/05/2019, 11:47 AM
    ❓ What's the cleanest way to test if all elements in a list are distinct? The best I could come up with was
    list.size == list.distinct().size
    , which is efficient, but ugly
    ☝️ 1
    h
    s
    +2
    • 5
    • 10
  • i

    Iaroslav Postovalov

    03/05/2019, 4:37 PM
    what means
    kotlin.jvm.JvmSynthetic
    ?
    k
    • 2
    • 3
  • r

    Richard Cumberland

    03/05/2019, 5:01 PM
    for example here
    j
    b
    z
    • 4
    • 5
  • m

    Matthew Hall

    03/05/2019, 5:39 PM
    Do the types in kotlin.collections implement any of the java.lang or java.util interfaces on the JVM? e.g. java.util.List, java.lang.Iterable
    k
    f
    a
    • 4
    • 12
Powered by Linen
Title
m

Matthew Hall

03/05/2019, 5:39 PM
Do the types in kotlin.collections implement any of the java.lang or java.util interfaces on the JVM? e.g. java.util.List, java.lang.Iterable
k

karelpeeters

03/05/2019, 5:44 PM
Here are the mappings: https://kotlinlang.org/docs/reference/java-interop.html#mapped-types
There's some magic to it but yes, Kotlin's
List
implements
Iteratable
and they're both mapped to the respective Java type.
f

fred.deschenes

03/05/2019, 6:02 PM
@Matthew Hall: I'm guessing you're asking for this issue : https://github.com/jdbi/jdbi/issues/1482?
m

Matthew Hall

03/05/2019, 9:46 PM
correct
k

karelpeeters

03/05/2019, 10:22 PM
Could you give some context? What exactly is going on in that issue?
a

araqnid

03/06/2019, 10:26 AM
List<E> (E : Enum<E>) is being mapped to java.util.List<? extends E> and it looks like jdbi doesn’t handle that
Kotlin adds the wildcard because it sees List as immutable and hence the E is an “out” parameter. imho it’s doing the right thing, and jdbi should just trim the wildcard to its upper bound
the JvmSuppressWildcard annotation works too, that’s what I used for Guice
well, except that Enum classes in Java are final if their values don’t actually override anything ..
k

karelpeeters

03/06/2019, 11:10 AM
I see, that's a lot of things coming together!
m

Matthew Hall

03/08/2019, 5:48 PM
I believe we've found a workaround for the current use case: when the type variable extends
Enum
, we get the erased type--which for an
out MyEnum
type variable just gives
MyEnum.class
.
We might have to give thought to whether it is legitimate for us to reduce
? extends Foo
to just
Foo
for our use case
View count: 1