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

    jeggy

    10/08/2019, 4:36 PM
    the
    typeOf<>()
    function was released as an experimental function in
    1.3.40
    . Is it possible to follow the progress of this or know how long before it will be marked as not experimental?
    e
    • 2
    • 2
  • j

    Justin

    10/08/2019, 7:45 PM
    I’m wondering if there is something that works like
    zip
    , but instead of returning pairs based on index, it returns pairs based on a predicate. For example:
    data class A(val id: String)
    data class B(val id: String)
    
    val listA: List<A> = listOf(A(“3”), A(“8”))
    val listB: List<B> = listOf(B(“8”), B(“2”), B(“4”))
    
    val pairs: List<Pair<A, B>> = listA.someTransformation(listB) { it.id == id }
    
    // ‘pairs’ would contain:
    // listOf((A("8"), B("8"))
    Would love to know if there’s a best practice around this type of operation?
    k
    j
    a
    • 4
    • 22
  • g

    groostav

    10/08/2019, 7:48 PM
    I've got a
    ...error: overload resolution ambiguity:
        [javac] @InlineOnly public inline fun Double.isInfinite(): Boolean defined in kotlin
        [javac] @InlineOnly public inline fun Double.isInfinite(): Boolean defined in kotlin
    when I build from ant, but my classpath looks OK. Is there any way I can get
    kotlinc
    to tell me where its getting these two functions from?
    k
    i
    • 3
    • 6
  • b

    benny.huo

    10/08/2019, 10:54 PM
    Secondary constructors are not forced to call the primary one in enum classes? Is it a bug or designed to be?
    i
    • 2
    • 2
  • w

    w_bianrytree

    10/09/2019, 9:23 AM
    Hey guys. Anyone knows what’s the execution order for init block and property?
    class A{
      val b:Int  = 0
      val a:Int
      init {
        a = 2
      }
    }
    Is there any order of a/b’s initialization? a first?
    d
    • 2
    • 4
  • w

    w_bianrytree

    10/09/2019, 9:27 AM
    The main problem I meet.
    class MyView:View{
      private val myChildView:View = findViewById(R.id.my_view_id)
      init{
         View.inflate(R.layout.my_layout,this)
      }
    }
    There is a chance that myChildView is null because inflation is executed after findViewById.
    l
    d
    +2
    • 5
    • 38
  • l

    Luigi Scarminio

    10/09/2019, 11:25 AM
    I have this double number that I want to check if is between an interval. I was using "in", but now is marked as deprecated. I understand that there was a mixin creating some confusion. So what is the proper way to do this?
    s
    s
    • 3
    • 6
  • s

    Stephan Schroeder

    10/09/2019, 2:48 PM
    I don’t understand why
    lastEndTokenIndex
    is
    -1
    😐 If I use
    lastIndexOf
    without
    fromIndex
    than the result is the expected 40. But 40 is bigger than 0, so this fromIndex shouldn’t interfere with the result, should it??
    fun main() {
        val sb = StringBuilder("<products><product>2</product><product>4</product></products>")
        val endToken = "</product>"
        val fromIndex = 0
        val lastEndTokenIndex = sb.lastIndexOf(endToken, fromIndex)
        println("lastEndTokenIndex: $lastEndTokenIndex")
    }
    Kotlin Playground: https://pl.kotl.in/SlHzdIq1j
    k
    r
    • 3
    • 14
  • r

    raj

    10/09/2019, 5:11 PM
    #dokka > Task :dokka FAILED :dokka (Thread[Daemon worker Thread 4,5,main]) completed. Took 17.05 secs. FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':dokka'.
    com/sun/tools/doclets/formats/html/HtmlDoclet
    * Try: Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/5.5/userguide/command_line_interface.html#sec:command_line_warnings
    w
    a
    • 3
    • 3
  • n

    neworldlt

    10/09/2019, 8:09 PM
    kotlinx.cli
    looks abandoned. Can I expect this tool will be well maintained?
    d
    • 2
    • 3
  • r

    Robert

    10/09/2019, 8:30 PM
    If I use a
    var
    or
    val
    in an interface, do I always have to use
    override
    to "implement" it? I tried using
    abstract
    in the
    interface
    , but that's no help
    s
    • 2
    • 21
  • d

    digitalsanctum

    10/09/2019, 9:22 PM
    Just curious if anyone has run Kotlin on ARM processors? Any caveats?
    k
    u
    • 3
    • 4
  • u

    ursus

    10/09/2019, 9:29 PM
    Why does this discrepancy vs java exist?
    class Bar : Foo<Quax>() 
    
    abstract class Foo<T>
    
    internal class Quax
    error is public subclass exposes internal supertype argument
    and this java works
    public class Rah extends Meh<Ohe> {
    }
    
    class Ohe {
    }
    
    public abstract class Meh<T> {
    }
    When internal is looser modifier than package private
    k
    • 2
    • 4
  • m

    Matt Thiffault

    10/09/2019, 10:32 PM
    Channel Question: How do I suspend while waiting for a message from a channel that matches a predicate, in a repeatable way? When I use ReceiveChannel.first{} or ReceiveChannel.consumeAsFlow().first {} more than once, the second one throws an exception saying channel cancelled and no items in flow respectively.
    d
    r
    • 3
    • 3
  • s

    standinga

    10/09/2019, 10:40 PM
    enum ThumbnailsSliderAction {
        case scrub(time: CMTime, event: ThumbnailsSliderEvent)
        case zoom(level: Int)
    }
    k
    • 2
    • 3
  • m

    Matt Thiffault

    10/10/2019, 12:45 AM
    I'm guessing no, but is it possible to do something cool like make an type implement an interface via extension functions? Eg. can I add a .close() extension to something and then pass it as AutoCloseable?
    n
    s
    n
    • 4
    • 7
  • j

    jbnizet

    10/10/2019, 6:37 AM
    Suppose I want to use
    for (date in d1..d2)
    where d1 and d2 are instances of java.time.LocalDate. I can do that by defining an extension function
    operator fun ClosedRange<LocalDate>.iterator()
    . But is there a way to easily have that extension function imported in IntelliJ? Except for manually typing the import statement
    import my.package.iterator
    at the top of the file, I haven’t found a way, which makes it quite unintuitive to use such a for loop. Is there a better solution that I’m missing?
    e
    • 2
    • 3
  • y

    yawkat

    10/10/2019, 9:58 AM
    is there a reason why emptyList has a type parameter and couldnt just return List<Nothing>?
    d
    b
    k
    • 4
    • 3
  • o

    ozzmhmt

    10/10/2019, 4:59 PM
    Hello, I want to write an in-class polling application. But how do I check if the student is in the classroom? I thought about doing it with QR code but it has disadvantages. Is there any other way you want to get your ideas.
    s
    c
    • 3
    • 5
  • r

    raj

    10/10/2019, 6:39 PM
    *phg@ubuntu:~/gateway-model$ javac -version javac 1.8.0_222 phg@ubuntu:~/gateway-model$ java -version openjdk version "1.8.0_222" OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~18.04.1-b10) OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode) phg@ubuntu:~/gateway-model$ ./gradlew build --info FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':compileKotlin'.> Kotlin could not find the required JDK tools in the Java installation '/usr/lib/jvm/java-8-openjdk-amd64/jre' used by Gradle. Make sure Gradle is running on a JDK, not JRE. * Try: Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/5.5/userguide/command_line_interface.html#sec:command_line_warnings *
    r
    j
    • 3
    • 2
  • s

    Sylvain Patenaude

    10/10/2019, 8:55 PM
    Cross-sharing with #general.
    • 1
    • 1
  • a

    amadeu01

    10/11/2019, 1:09 AM
    folks, in your opinion, what are the core features that make kotlin unique?
    g
    p
    +2
    • 5
    • 22
  • m

    Mani

    10/11/2019, 9:27 AM
    l
    d
    • 3
    • 23
  • j

    jbnizet

    10/11/2019, 10:28 AM
    I expected to find a private setter in the byte code when compiling the following class, but there is none. Is that documented behavior, or is it an undocumented optimization. Doesn’t that optimization break reflection-based code that expects the setter to be there?
    class Dog {
         var frightenedCats = 0
             private set
    
         fun frightenCat() {
             frightenedCats++
         }
     }
    Here’s the output (I just omitted the constructor) when decompiling the bytecode with `javap -p -c`:
    private int frightenedCats;
    
      public final int getFrightenedCats();
        Code:
           0: aload_0
           1: getfield      #10                 // Field frightenedCats:I
           4: ireturn
    
      public final void frightenCat();
        Code:
           0: aload_0
           1: dup
           2: getfield      #10                 // Field frightenedCats:I
           5: dup
           6: istore_1
           7: iconst_1
           8: iadd
           9: putfield      #10                 // Field frightenedCats:I
          12: return
    Note: I’m absolutely fine with that optimization. Just curious about it.
    j
    • 2
    • 1
  • t

    thiagoretondar

    10/11/2019, 2:43 PM
    Thanks @sdeleuze and #spring team for supporting and integrating more and more with :kotlin: https://twitter.com/relizarov/status/1182651349449760768
    👍 3
    s
    p
    • 3
    • 25
  • m

    Mani

    10/11/2019, 7:38 PM
    Trying to implement strategy pattern. Let me know if this is bad code
    p
    • 2
    • 12
  • e

    Ellen Spertus

    10/11/2019, 8:05 PM
    I currently have code like this:
    override fun onReject(token: String) {
            if (savedConnectionState is ConnectionState.Authenticating) {
              // do something
            } else {
               // complain
            }
        }
        
        override fun onSend(message: String) {
            if (savedConnectionState is ConnectionState.ReadyToSend) {
                // do something
            } else {
                // complain
            }
        }
    Is there a way to create a
    check()
    method that takes a type (e.g.,
    ConnectionState.Authenticating
    ) as an argument and tests whether the instance variable
    savedConnectionState
    is that type?
    p
    • 2
    • 21
  • b

    Ben Madore

    10/11/2019, 8:31 PM
    i asked something similar a while back, but this is slightly different. is there a standard extension function that takes a block, and only executes that block if receiver is null. something like:
    fun <T> T?.whenNull(block: T?.() -> Unit): T? {
        if (this == null) {
            block()
        }
        return this
    }
    to be used like:
    return getFoo().whenNull {
      <http://log.info|log.info> {"can't find a foo"}
    }
    j
    i
    • 3
    • 7
  • l

    Luis Munoz

    10/11/2019, 8:48 PM
    Untitled
    s
    • 2
    • 2
  • j

    Jason

    10/12/2019, 12:35 AM
    It's not really lazily, it's just that it won't happen until you call/use
    Items
    in your code:
    fun main() {
      val i = Items   // <-- properties created here
      println("a")
      println(i.x)
      // etc
    }
    ➕ 1
    h
    • 2
    • 3
Powered by Linen
Title
j

Jason

10/12/2019, 12:35 AM
It's not really lazily, it's just that it won't happen until you call/use
Items
in your code:
fun main() {
  val i = Items   // <-- properties created here
  println("a")
  println(i.x)
  // etc
}
➕ 1
h

Hamza

10/12/2019, 12:36 AM
Ah, I see. That makes sense
j

Jason

10/12/2019, 12:37 AM
👍
h

Hamza

10/12/2019, 12:37 AM
Thanks!
View count: 2