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

    Sandy

    09/26/2019, 5:08 PM
    We have extension functions. But i dont want to write a for loop
    s
    • 2
    • 5
  • d

    Dico

    09/26/2019, 6:13 PM
    Let's say I have these 2 Java methods:
    public String get(Integer key) {...}
    public String get(int key) {...}
    How can I call one of these without running into overload resolution ambiguity?
    d
    k
    • 3
    • 57
  • i

    Ifvwm

    09/27/2019, 1:48 AM
    How I can return a function within itself? it’s like def f(x): print(x) return f then I can do f(1)(2)(3)
    j
    s
    +2
    • 5
    • 32
  • n

    Nikolay Kasyanov

    09/27/2019, 8:00 AM
    Hey folks, I'm having an issue trying to use an
    internal
    class from a test within the same module (test & class packages are different though). According to the docs, it should work: https://kotlinlang.org/docs/reference/visibility-modifiers.html#modules (see "Modules", 3rd option). I'm using Kotlin Multiplatform though, hence my source sets are called
    commonMain
    and
    commonTest
    , not just
    main
    and
    test
    . Could this be causing this access issue? Is this a bug?
    a
    • 2
    • 3
  • i

    Iaroslav Postovalov

    09/27/2019, 10:44 AM
    Hi! How can I specify the classpath of kts Script Engine? upd: I want to load a kts file but encapsulate the implementation of my program
    l
    • 2
    • 1
  • j

    Jakub Komorowski

    09/27/2019, 12:13 PM
    Hello, fellow Kotliners! Recently I’ve came across a following problem. I was implementing a custom Android view, and the base View I was extending had
    setEnabled
    method. I’ve overridden it in my class, and used properties from the child class in this overwrite. As the properties I’ve used were unmutable and non-nullable I was startled when my app crashed with
    NullPointerException
    thrown in that method. Turns out it was called from the superclass constructor, and properties are initialized only after superclass constructor call. The simplified code that caused my problem looks something like: https://bit.ly/2n6xmm5 . When you run it, it throws
    NullPointerException
    when using seemingluynon-nullable property. Is there a pattern that would allow us to omit method calls on unitialized unmutable properties? I found two solutions to that problem, but I don’t think they’re very elegant. One using lateinit vars https://bit.ly/2nPYBBX - pretty ugly, and one using a flag https://bit.ly/2mgG4hq - pretty weird. All of the urls are shortened https://play.kotlinlang.org code snippets.
    i
    s
    d
    • 4
    • 9
  • m

    Mani

    09/27/2019, 12:49 PM
    Guys, I have two lists of same length. Want to iterate them in parallel. Is there a good kotlin way of doing it or just use a for loop with index approach?
    s
    • 2
    • 2
  • a

    Andreas Unterweger

    09/27/2019, 1:01 PM
    hello everyone, i am looking for a control function
    elseIf
    it should allow me to take another value if the predicate does return true. i implemented the following extension function:
    inline fun <T> T.elseIf(predicate: T.() -> Boolean, supplier: () -> T) : T =
            when {
                predicate() -> supplier.invoke()
                else -> this
            }
    its called like
    val i = "ssss".elseIf({isEmpty()}) {"other"}
    which feels very clumsy. can i optimize the syntax more? or arent there already alternatives in kotlin? or maybe im just missing the easy solution?
    o
    k
    +3
    • 6
    • 15
  • k

    karelpeeters

    09/27/2019, 1:01 PM
    I feel like a broken record but just use if!
    ☝️ 4
    :thread-please: 1
    💯 14
    ➕ 4
    r
    m
    +3
    • 6
    • 15
  • z

    zkeme

    09/27/2019, 5:13 PM
    Hi guys! Is there any way to use triple backticks in KDoc and still have links inside?
    r
    • 2
    • 25
  • g

    groostav

    09/27/2019, 9:22 PM
    Hey guys, does anybody know how to use the fully qualified name to an extension function? eg
    package asdf
    
    fun Any.doThing() = TODO()
    
    //...
    package main
    
    //no import statements
    
    fun outer(){
      42.doThing() //<-- auto import `asdf.dothing`? 
      //No! I want to write the fully-qualified invocation instead!
    
      asdf.doThing(42) //error
      42.asdf.doThing() //error
      42.`asdf.doThing`() //error
    }
    b
    s
    +2
    • 5
    • 5
  • x

    xenoterracide

    09/27/2019, 9:56 PM
    coroutines on the jvm, is there some kind of underlying executor service that can be grabbed?
    r
    g
    • 3
    • 4
  • m

    Mani

    09/28/2019, 10:53 AM
    Folks, how do I choose which one to use between ArrayList and MutableList? and what are the ups and downs?
    m
    k
    • 3
    • 3
  • c

    Chris Cunningham

    09/29/2019, 4:05 AM
    is there a way to redefine the same class or interface multiple times with only its amount of generic types differing
    interface Event<out TS> { ... }
    interface Event<out TS, out T0> { ... }
    interface Event<out TS, out T0, out T1> { ... }
    k
    l
    • 3
    • 8
  • t

    tschuchort

    09/29/2019, 10:34 PM
    I have to override a Java method that uses an
    @NonNull
    annotation on a parameter even though documentation (and common sense) says that it can be null. If I make the same parameter nullable in my overriding Kotlin method, the compiler complains to me that I'm not overriding. But if I don't, then the function will crash at the hidden parameter assertion that is generated automatically. How do I tell the compiler "shut up, I know what to do"? Can I disable null-assertions for just this method?
    k
    t
    • 3
    • 19
  • k

    Kamil K

    09/30/2019, 10:34 AM
    Hey guys! While reviewing PR I've spotted a smelly code.
    fun x(anInt: Int) : String {
        when (anInt) {
            0 -> return "zero"
            1 -> return "one"
        }
        return null!!
    }
    Despite the 'quality` of code itself I'm curious why compiler thinks that
    return null!!
    is fine (IDE hints that return statement is unreachable which is false)? And similarly why this
    val a : Int = null!!
    is allowed as well.
    g
    m
    +2
    • 5
    • 7
  • u

    user

    09/30/2019, 11:35 AM
    message has been deleted
    s
    • 1
    • 1
  • s

    Steve Young

    09/30/2019, 11:47 AM
    Does anyone know if Kotlin native supports multithreading on IOS?
    a
    • 2
    • 2
  • a

    Andrew Gazelka

    10/01/2019, 1:02 AM
    is there an idiomatic way to process an infinite sequence in parallel?
    g
    d
    m
    • 4
    • 35
  • a

    Akbar

    10/01/2019, 8:05 AM
    hi @all I need to know whether to use data binding in MVVM?
    m
    g
    • 3
    • 3
  • j

    jeggy

    10/01/2019, 9:57 AM
    I'm not sure if this is a bug or not? but I have a large project, and when ever I'm doing some small change that makes my code uncompilable and I press run in IntelliJ. It shows me all the errors but it compiles anyway and the stuff actually works, I think it's using some old already compiled code. But is it supposed to do this?
    m
    w
    • 3
    • 2
  • d

    dalexander

    10/01/2019, 2:24 PM
    I just ran into a seeming shortcoming in the type inference system, can't find any tickets on youtrack, has anyone else run in to this?
    // both Foo and Bar extend Item
    val item: Any? = getSomething()
    if(item is Foo || item is Bar) {
      // I would expect this to smart cast to Item -- defining Item as a sealed class doesn't seem to help either
      doThingWithItem(item) //Error - Type mismatch, required: Item, found Any?
    }
    d
    s
    +4
    • 7
    • 25
  • s

    Stephan Schroeder

    10/02/2019, 10:32 AM
    I wouldn’t have expected that
    "<test>.*</test>".toRegex()
        .find("aaaa<test>5</test>aaaa<test>4</test>aaaa")
        ?.let { println("match: ${it.value}") }
    doesn’t return the minimal first match <test>5</test>, but the longer one <test>5</test>aaaa<test>4</test> given that the documentation says: “Returns the first match of a regular expression” here: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-regex/find.html And unfortunately findAll equally just returns a single match instead of two. Is there a way for me to fix this? Playground link: https://pl.kotl.in/HA-C02_Gy
    a
    m
    m
    • 4
    • 7
  • s

    Slackbot

    10/02/2019, 2:45 PM
    This message was deleted.
    m
    v
    • 3
    • 6
  • s

    Steve Young

    10/02/2019, 3:42 PM
    How do I remove the prefix generated for objective c class names?(to className instead of frameworkNameClassName)
    b
    a
    • 3
    • 4
  • g

    GarouDan

    10/02/2019, 5:37 PM
    Hi, if we have a method on a abstract class, like this:
    abstract fun test() : String
    can we, using somehow the new kotlin techniques to change the returning value of the function in the other abstract class which extend the first one, something like this?
    fun test(): String {
        return test().toString()
    }
    
    fun test(): Int {
    }
    The goal would be use to reuse the same name. Maybe something using the
    by
    keyword somehow? Composing the objects (where the problem here is that I have two abstract classes)
    s
    d
    +3
    • 6
    • 9
  • n

    Nezteb

    10/02/2019, 8:39 PM
    So I’m adding Kotlin to a previously Java-only project. I’m following these instructions https://kotlinlang.org/docs/reference/using-maven.html But now my
    mvn clean package
    commands frequently time out with a “Java heap space” error when using
    maven-assembly-plugin
    . Increasing my java/maven memory doesn’t fix it. I’ve added a single “hello world” type of Kotlin file, so I’m not sure why just adding the compiler for Kotlin pushes the entire build way over the edges. Has anyone else hit this before when adding Kotlin to a Java project?
    a
    • 2
    • 1
  • t

    tschuchort

    10/02/2019, 9:39 PM
    I have a pretty big hierarchy of sealed classes where all the leafs are data classes. Basically every subclass is just the superclass plus some extra values. Sometimes the subclasses are even identical except for the name, which signifies a different kind of the object. How can I construct values of this class hierarchy without having lots of code duplication? Delegation is hardly possible, since the common superclasses are sealed and thus can't be extended to make delegate objects for them. Basically what I want to do is to have one function that makes `Car`s and then take that
    Car
    and promote it a
    BMW
    or
    Toyota
    by adding some values to it.
    k
    k
    • 3
    • 2
  • s

    Steve Young

    10/02/2019, 10:56 PM
    is it possible to ignore SSL certificate error when using the Ktor IOS httpClient?
    s
    • 2
    • 1
  • m

    Mahendran

    10/03/2019, 11:29 AM
    Any sample code for Kotlin Annotations Processing
    k
    • 2
    • 1
Powered by Linen
Title
m

Mahendran

10/03/2019, 11:29 AM
Any sample code for Kotlin Annotations Processing
k

karelpeeters

10/03/2019, 12:25 PM
#kapt
View count: 3