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

    Steve

    04/28/2020, 5:53 PM
    you would want to compile the library, and add it to the project
    c
    a
    • 3
    • 9
  • v

    voben

    04/29/2020, 2:17 AM
    If I know a value is null initially but won’t be null when accessed. Is it preferred to
    !!
    ?.
    s
    i
    • 3
    • 2
  • h

    huehnerlady

    04/29/2020, 7:02 AM
    Hi guys, Just wondering if I can find an overview somewhere which kotlin version supports which java? Here I can see under 
    jvmTarget
     that version 1.3.72 seems to support Java13, but when I try it out I get the error “Unsupported class file major version 57”, which made me wonder if it was supported after all? 🤔
    d
    c
    a
    • 4
    • 5
  • t

    Tom Carton

    04/29/2020, 9:44 AM
    Hey! I'm quite stuck on a custom project I'm working on and I'm pretty sure I could greatly learn and improve it with your insights! I'm trying to develop a custom
    Chat Mobile Application
    as such: - a server in
    Kotlin
    - clients using
    KotlinMultiplatform/Kotlin-native
    I want to use sockets to exchange encrypted messages (using a simple xor for instance) in the common/shared part using Posix. Each client displays all the messages and can send new message to the server. The server serves all the clients with any message it received. Nothing fancy on that side... And the main thing I am trying to demonstrate with all this, is how I could share the maximum of code between platforms using
    Kotlin-native
    and have clients code only responsible for the UI. Period. So I tried to use
    Coroutines
    to have a background thread listening to incoming messages. These messages could come from socket (in order to be dispatched to the UI) or from UI (in order to be dispatched to socket). But sounds like it doesn't work like this as my application often get stuck or the coroutines stop running. I tried to use a heartbeat to wakeup the coroutines or some time-out to prevent getting stuck but this is clearly black magic and doesn't succeed anyway. Do you have any idea or insight to point out on what I should rather do? or on what I am doing wrong? Thank you!
    c
    s
    • 3
    • 8
  • c

    Chilli

    04/29/2020, 9:29 PM
    For some reason my code stops between those 2 printlns. It prints
    init start
    and after a few seconds, displays
    Test running process exited unexpectedly.
    Any idea what might it be? str is String used is MutableSet<String>
    c
    a
    +3
    • 6
    • 18
  • p

    poohbar

    04/30/2020, 1:41 PM
    How do I do this if entity is nullable?
    entity::class
    t
    • 2
    • 7
  • y

    Yevhenii Nadtochii

    04/30/2020, 2:04 PM
    Hello! Does anybody know how can I use inner classes to delegate interface implementation ?
    interface Action
    class Outer(doer: Doer = this.Doer()) : Action by doer { //'this' is not defined in this context
        inner class Doer : Action
    }
    or
    interface Action
    class Outer : Action by Doer() { //Constructor of inner class Doer can be called only with receiver of containing class
        inner class Doer : Action
    }
    t
    • 2
    • 4
  • n

    Nicolò

    04/30/2020, 9:36 PM
    Hello, I’m having an hard time having a spring boot kotlin app to hotreload/hot swap with intellij. Is there anything i’m missing? I tried to set the auto build setting and the registry to alllow when doing it when the app is running but still not luck!
    m
    • 2
    • 1
  • a

    Alex Kuznetsov

    05/01/2020, 8:01 PM
    Hi there, Is there a way to have a multi-line statement, a way to tell Kotlin that the statement continues on next line: I'd like to spread a long statement like the following over several lines:
    every { <http://myThing.do|myThing.do>() } returns 1 andThenThrows Exception("No way!") andThen 3 andThen 4
    the line gets too wide, is there a way to continue it:
    every { <http://myThing.do|myThing.do>() } returns 1 
      andThenThrows Exception("No way!") 
      andThen 3 
      andThen 4
    TIA!
    s
    • 2
    • 1
  • s

    Sudhir Singh Khanger

    05/04/2020, 12:47 PM
    private fun twoSome(nums: IntArray, target: Int): IntArray {
        val returnArray: IntArray = intArrayOf()
        var initialVal = nums[0]
        for (num in nums) {
            if (initialVal + num == target) {
                returnArray[0] = initialVal
                returnArray[1] = num
                break
            }
            initialVal = num
        }
        return returnArray
    }
    Why am I getting
    ArrayIndexOutOfBoundsException
    when assigning a value to the
    returnArray
    ?
    t
    e
    • 3
    • 2
  • v

    voben

    05/06/2020, 2:25 PM
    Is it possible to make a sealed class parcelable? I’ve annotated the child classes with `@Parcelize`but when I add the annotation to the parent, I get an error saying “Parcelable should not be a ‘sealed’ or ‘abstract’ class”
    b
    • 2
    • 2
  • ł

    Łukasz Patro

    05/11/2020, 9:59 AM
    Hi, I could not build Kotlin project using Maven and JDK 6:
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 1.635s
    [INFO] Finished at: Mon May 11 11:52:50 CEST 2020
    [INFO] Final Memory: 7M/231M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.3.72:compile (compile) on project untitled: Execution compile of goal org.jetbrains.kotlin:kotlin-maven-plugin:1.3.72:compile failed: Unable to load the mojo 'compile' in the plugin 'org.jetbrains.kotlin:kotlin-maven-plugin:1.3.72' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: org/jetbrains/kotlin/maven/K2JVMCompileMojo : Unsupported major.minor version 52.0
    It builds fine with JDK 8.
    pom.xml
    is very simple:
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="<http://maven.apache.org/POM/4.0.0>" xmlns:xsi="<http://www.w3.org/2001/XMLSchema-instance>" xsi:schemaLocation="<http://maven.apache.org/POM/4.0.0> <http://maven.apache.org/maven-v4_0_0.xsd>">
    
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>org.example</groupId>
        <artifactId>untitled</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
    
        <name>org.example untitled</name>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <kotlin.version>1.3.72</kotlin.version>
            <kotlin.code.style>official</kotlin.code.style>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-stdlib</artifactId>
                <version>${kotlin.version}</version>
            </dependency>
        </dependencies>
    
        <build>
            <sourceDirectory>src/main/kotlin</sourceDirectory>
            <testSourceDirectory>src/test/kotlin</testSourceDirectory>
    
            <plugins>
                <plugin>
                    <groupId>org.jetbrains.kotlin</groupId>
                    <artifactId>kotlin-maven-plugin</artifactId>
                    <version>${kotlin.version}</version>
                    <executions>
                        <execution>
                            <id>compile</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>compile</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>test-compile</id>
                            <phase>test-compile</phase>
                            <goals>
                                <goal>test-compile</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>
    It seems that
    kotlin-maven-plugin
    do not support Java before version 8...
    a
    • 2
    • 5
  • c

    Cupi Vo

    05/12/2020, 12:40 AM
    Hello, Abstract Class vs. Interface: Except that it can only inherit 1 class, is there anything else in the interface that abstract classes cannot? Thanks.
    ł
    d
    • 3
    • 8
  • a

    Anton

    05/12/2020, 2:31 PM
    Hi there. Is it possible to write a function, that accepts a function with any number of arguments, of any kind, and execute it? The following works, but only for lambda functions
    fun <R>myFunc(block: () -> R): R
    {
        println("starting)
        try
        {
            return block()
        }
        finally
        {
            println("end")
        }
    }
    As in the example above, I would like to do some things before the functions run, and some things after. An example would be to measure the execution time. Appreciate any help!
    r
    m
    • 3
    • 2
  • k

    Kevin

    05/13/2020, 6:14 PM
    Hi all, i would like to know if it is possible to show/hide UI element over a two separated activity? in example, i had to 2 activities, first is the main activity(home) and second is the support activity(something like information or pop up). from this examples i want to somehow show the support activity overlaying the main activity, so far i able to do this by doing
    include
    of the support activity layout on the main activity file. the next thing i want to do, is that i want to be able to interact with the support activity, which is the basic interaction was only a show/hide elements. i was thinking that i should be able to do this by using
    visibility = View.GONE
    or
    visibility = View.VISIBLE
    on the textview element, but no matter what i do, everytime i click on the textview, it results in the app crashing. i'm quite stuck on this part, do anyone have any idea or insight on where do i wrong? or what should i do? thank you!
    a
    • 2
    • 3
  • s

    still-dreaming-1

    05/13/2020, 8:10 PM
    What does it mean to have a property that is a val (not var) with a get() function attached, and no set() function. It kind of seems like a contraction of terms to have a "val" that changes every time you "get" it. Will the get be called each time or is it gotten once and then reused?
    s
    c
    • 3
    • 6
  • m

    Mauricio Barbosa

    05/13/2020, 8:36 PM
    Hi guys, I'm trying to convert an rxjava api based into a suspend function. Can I do something like this?
    class UserApiClient(private val rxJavaBasedApi) {
        suspend fun getUser(): User = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
            rxJavaBasedApi.getUser().blockingGet()
        }
    }
    Or there's a better approach?
    d
    • 2
    • 4
  • k

    Kevin

    05/14/2020, 3:48 PM
    Hi All, I'm trying to change the background of 2 layouts by using onClick. let's say there is Layout A and Layout B, the default form is that Layout A is active and Layout B is inactive, when the user click the button, Layout A become inactive and Layout B become active. active layout will use vector assets as background, while inactive layout will use simple color code(hexcode). to do that i was thinking this can be done by a simple ifelse function, did i do it right with this? or there is a better way to do this?
    var isColorChanged: Boolean? = true;
    
    fun changeScreenClick(view: View) {
            if(isColorChanged==true){
                view_menu_1.resources.getColor(R.color.Yellow)
            }
            else{
                view_menu_2.resources.getDrawable(R.drawable.background_box)
            }
        }
    Thank you!
    s
    • 2
    • 4
  • k

    Karlo Lozovina

    05/16/2020, 10:31 PM
    Total Kotlin/Java/JVM beginner here: managed to deserialize some complex JSON with
    kotlinx.serialization
    , just can't figure out how to deserialize to
    LocalDateTime
    c
    • 2
    • 2
  • a

    Ananiya

    05/17/2020, 7:51 AM
    if I parse json list file from api server and change it to dataclass if it is
    val l = listOf(d1, d2, d3 ,d4 ,d7)
    . how do i select the last element in the list but i cannot use
    l[5]
    or
    l.get(5)
    because they may change the list length in any time ?
    s
    • 2
    • 4
  • m

    Mark

    05/17/2020, 12:19 PM
    Is there anything in the standard library for building an iterator from a list of iterables?
    i
    • 2
    • 4
  • s

    supra

    05/18/2020, 5:49 AM
    when (func()) {
        in S -> println("$it in S")
        null -> println("null")
        else -> println("$it not in S")
    }
    c
    • 2
    • 2
  • m

    Mark

    05/18/2020, 6:55 AM
    Is there a simpler version of zip, that doesn’t build a sequence? Rather, we just do the work in the transform block?
    m
    k
    • 3
    • 11
  • b

    bodiam

    05/18/2020, 10:52 AM
    I'm having a few instances of this in my code:
    return doubleArrayOf(base, tokenSort, tokenSet).max()!!.toInt()
    And I'd like to get rid of the
    !!
    here, especially since I know this call will never return null. Any suggestions on how to do this?
    d
    • 2
    • 2
  • h

    Hixie

    05/19/2020, 3:32 AM
    is there a kotlin native websocket client library or should we just proxy that to platform-specific code?
    m
    u
    • 3
    • 32
  • f

    frogger

    05/19/2020, 10:55 AM
    overriding this java method, how can I add a new item to the map?
    override fun extractAuthentication(map: MutableMap<String, *>)
    e.g. when I want to add a list the compiler says: “Required Any? found List<String>”
    d
    m
    • 3
    • 6
  • j

    Joshua Akinsola

    05/20/2020, 10:49 AM
    Hey, I am getting started on android studio and I ran into "no target device found" when trying to run code, any tips on solving this?
    :google: 2
    e
    • 2
    • 4
  • r

    Raj Trivedi

    05/20/2020, 11:15 AM
    please firrst create device from "AVD Manager"
    👍 1
    j
    • 2
    • 4
  • j

    JP

    05/20/2020, 2:42 PM
    Is there a way to abort early (break) while using
    fold
    ? Or is a normal
    for
    loop the only option?
    j
    • 2
    • 4
  • j

    Joshua Akinsola

    05/20/2020, 3:36 PM
    Does anyone know of any courses that show how to build an app on top of Google cloud's infra?
    j
    • 2
    • 3
Powered by Linen
Title
j

Joshua Akinsola

05/20/2020, 3:36 PM
Does anyone know of any courses that show how to build an app on top of Google cloud's infra?
j

JavierSalazar

05/21/2020, 3:15 PM
I think there are plenty of GCP related courses in Udemy
j

Joshua Akinsola

05/21/2020, 9:32 PM
tbh there isn't from an app development perspective
I think i might have found one on pluralsight
View count: 10