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

    Brian Dilley

    10/21/2020, 3:44 AM
    Milestone
    n
    s
    • 3
    • 11
  • m

    Mostafa Hadian

    10/21/2020, 12:27 PM
    Any recommended Kotlin course for Android developers …. I am looking for some courses to share with my team. ( I hope this is the right channel )
    m
    m
    • 3
    • 3
  • s

    Sourabh Rawat

    10/22/2020, 6:13 PM
    What would be the kotlin way to write below code:
    var toPlayer = players.random()
                    while (toPlayer == fromPlayer) {
                        toPlayer = players.random()
    }
    I am not liking the multiple assignments + var here...
    s
    n
    +3
    • 6
    • 18
  • i

    Irving Rivas

    10/23/2020, 2:47 PM
    @Alec Muffett bitwise are only available for Int and Long
    a
    r
    u
    • 4
    • 5
  • p

    poohbar

    10/24/2020, 9:53 PM
    any reason why I can’t call this java method?
    e
    • 2
    • 4
  • a

    Alec Muffett

    10/25/2020, 3:48 PM
    Here is some code which does not work. I suspect that the reason that it does not work is that
    this
    in the
    buildString
    lambda does not refer back to the
    ByteArray
    , but instead to the implicit
    StringBuilder
    which is being built, and I suspect that the
    forEach
    is inheriting its iterator from the inner
    this
    , rather than the (shadowed) outer
    this
    . HOWEVER: the code is cute, and I would like understand the problem to be certain, and to save the situation. Can I elegantly fix the shadowing problem in the existing code, rather than refactoring it to use a loop, or
    with
    or
    apply
    ?
    const val INT_TO_HEX = "0123456789ABCDEF"
    fun ByteArray.toHexStringDoesNotWork() = buildString {
        forEach {
            val octet = it.toInt()
            append(INT_TO_HEX[octet.and(MASK_UPPER_NIBBLE).ushr(4)])
            append(INT_TO_HEX[octet.and(MASK_LOWER_NIBBLE)])
        }
    }
    a
    v
    • 3
    • 5
  • p

    poohbar

    10/25/2020, 4:50 PM
    something like
    lists.chunked(size / n)
    s
    t
    +2
    • 5
    • 6
  • c

    cognio

    10/27/2020, 3:55 PM
    Hey guys. Does anyone know is it possible to access object property by it's name or KProperty dynamically? Like in JS
    user["username"]
    r
    • 2
    • 2
  • p

    Pymous Thomas

    10/27/2020, 4:28 PM
    Hello there ! Thanks for inviting me around, Kotlin seems like a real good option for us. I actually have a question to start things off, just to avoid loosing time in an impossible project : We have a Web App, that allow us to do WebRTC video/audio call, we now need to have that same call displayed on a Google Assistant Smart Display (Lenovo 10"). So I have 2 questions : • Is it possible using Google Asssistant to transmit video/audio to the Smart Display • If yes, is it possible using Kotlin ? Thanks !
    s
    • 2
    • 2
  • s

    speed_star

    10/29/2020, 3:27 AM
    Hi. Do you know about good library for http client? I want to call external api via http client. My project is Spring boot (server side, not Android) I'm using https://github.com/square/okhttp now. Because there are some merits about performance. (e.g: Connection pooling, Transparent GZIP) There is another good library?
    n
    t
    • 3
    • 10
  • r

    Robert

    10/29/2020, 8:35 PM
    How do I create a property, if I don’t want it to be null, and don’t want to initiate a (default) value unless it is being called (unless manually a value has been set). Do I need field + getter + setter + private backing field? Or is there an easier way?
    r
    e
    • 3
    • 32
  • r

    Robert

    10/29/2020, 10:29 PM
    Why can’t I do this:
    val myByte: Byte = 0;
    val myInt: Int = 0;
    myByte == myInt;
    but CAN i actually do this?
    myByte.compareTo(myInt) == 0;
    Isn’t it the same?
    v
    • 2
    • 2
  • u

    UnAn

    10/29/2020, 11:32 PM
    Hi! I'm new to kotlin and android app development and I've been really interested in making apps. My question is if there is like a "list"/"guideline" of everything that I will need to learn in order to make an overall complete app. I was thinking of consulting this list then going to the documentation or code labs present in the developer's site and learn it from there. Is this method a good way to learn app development or is there a better way(in a free way)?
    d
    • 2
    • 2
  • j

    Juan B

    10/30/2020, 4:51 AM
    Hi all, I have a question about what would be a good way to implement a pattern where you have different components with responsibilities but the outcome of some may be an input of another component. I'm asking from the mutability/arguments perspective. E.g imagine a Chain of responsibility-ish (CoR) pattern where an object "Result" goes through multiple filters, each one generate an outcome based on some logic. This Result object is a complex object composed by some collections, other objects. Each Filter can add new pieces of information to the Result; and the order is important and can change. I'm wondering what would be a clean way to implement this in Kotlin. (Note that the computation is not stopped after the first processor handles the computation, it is reason I said CoR-ish) Some options I thought: • Common interface for filters with a Result class as an argument. Result as data class passed as argument in the call to each filter, inside I could clone and add new items but Clone is not deep so it wouldn't work with collections and more complex objects. • Do not use a data class but a normal class. I would have to implement getter and setter. I guess I could implement my own clone or use memory serialization/deserialization to force a deep clone (really don't want to do it) • Define specific Result Object per Filter so argument is inmutable. The main issue here is the order of execution can not be altered (it breaks the flexibility on the chain of responsibility pattern) Any suggestion or different approach? . Most of the examples I found for Single Responsibility in Kotlin does not cover the fact that the outcome from one filter may be needed in the next.
    • 1
    • 1
  • a

    Alec Muffett

    10/30/2020, 7:12 AM
    Hi All! So
    SequenceInputStream()
    takes a Java
    Enumeration
    as an argument, but at the moment I only have a `List<InputStream>`; there's a workaround for this described at https://www.pushing-pixels.org/2018/08/15/converting-list-to-enumeration-in-kotlin.html to provide a
    List<T>.toEnumeration()
    method, but I am wondering if there's something more elegant?
    v
    n
    • 3
    • 19
  • a

    Ananiya

    10/30/2020, 10:40 AM
    Hello there 👋, i am confused. I take user input then in the user input it might be "bot take rest" and I converted it to list, then I need to verify(put in if else statement) the first 9 words or if the 9 word is "bot take" or another command. How can I do that 9 words ?
    n
    v
    • 3
    • 8
  • s

    Slackbot

    10/30/2020, 5:21 PM
    This message was deleted.
    ✅ 1
    o
    n
    j
    • 4
    • 3
  • h

    Himansh Singh

    10/31/2020, 2:30 AM
    When using mutableListOf() or any collections object ; If without using the generics we initialise it with different data types then it starts behaving as a mutable list ? But if I mention generics (<Any> in this case) explicitly only then it works why ? for ex: val list = mutableListOf(1,2,"hIM"); --> this will behave as a mutable list and will not be able add anything to the list. whereas val list = mutableListOf <Any> (1,2,"him"); --> This just works fine and work as mutable list .
    v
    • 2
    • 2
  • z

    zero_coding

    11/01/2020, 11:00 AM
    Do I have to install any plugin?
    k
    • 2
    • 1
  • s

    Steven Wang

    11/01/2020, 11:40 PM
    A bit silly questions: if precision is not an issue, what is the pros & cons to use Float over Double in JVM target platform?
    v
    e
    • 3
    • 20
  • k

    Kenneth

    11/04/2020, 3:47 PM
    Hi! I have to call a service to get the status of a job after I have started it(so that I can set it as completed), and the service can use several minutes to complete the job. Is it a good idea to do this in a coroutine and then create another coroutine if the process is not done? Or should I do this another way? I need some kind of retry mechanism.
    w
    • 2
    • 1
  • o

    oday

    11/06/2020, 10:59 AM
    does
    in
    cause the runtime of the program to become as if it were 2 for loops O(n2)?
    t
    n
    • 3
    • 6
  • s

    Sean

    11/06/2020, 7:20 PM
    (This is longer than I hoped, sorry if I'm ranting too much here) I'm working on an app for a friend, it needs to run on android and a webapp on pc, the android app would be used to create/edit some data in a cloud database and the webapp would be used to generate reports from the data in the database, and sometimes edit things if needed. I did a quick demo app but I'm restarting because the code there was godawful, and now I'm trying to figure out what libraries to use and how to set the whole thing up properly. I'm a bit stuck figuring out the best way to do something like this. I can manage making a native android app and a webapp that both connect to a local database, I went to school for a couple years for software development and I've completed google's android kotlin fundamentals codelabs so I'm a rookie but I have a general idea of what to do for each seperate app. I'm mostly confused about connecting to a cloud database, since everything I've done so far is using a local database. Would using something like Kotlin Multiplatform be worth it here to reuse the backend logic for interacting with the database? I've been doing a ton of research and it seems like most of the KMP projects are for android/iOS and not android/webapp. I found KaMPKit as a starting point if I want to use KMP, and I was looking into ktor vs spring boot for the webapp/server side stuff. There's so many libraries/frameworks and different ways to do this that I'm stuck, anyone have some advice for an overwhelmed rookie? Thanks!
    👀 1
    w
    • 2
    • 4
  • d

    Draget

    11/06/2020, 9:28 PM
    I am reading https://kotlinlang.org/docs/reference/using-gradle.html to setup Kotlin with Gradle currently. When specifying dependencies, the document introduces the syntax first, where one does specify the deplendencies especially for the Kotlin SourceSets only. Not the top-level dependency-block. Is there any reasoning behind this? Any advantage compared to 'just' specifying the dependencies directly at top-level?
    d
    • 2
    • 2
  • t

    tenprint

    11/09/2020, 4:34 PM
    What is the "kotlin way" of doing this: In Java you could throw checked exceptions, which would give you compile-time feedback letting you know where in your code you need to implement try/catch. So for example if you threw an exception in a method that's used in many places, the compiler will force you to handle where ever it is called. However in kotlin, exceptions are unchecked, so you do not get any compile-time feedback. You may accidentally miss some places where you need to try/catch. What is the "kotlin way" here?
    👍 1
    r
    v
    +3
    • 6
    • 10
  • x

    xiaobailong24

    11/10/2020, 4:58 AM
    https://kotlinlang.org/docs/reference/ Kotlin lastest version is 1.4.10. But I want refer to v1.3.72 docs, how do that? Help me. What link is kotlin old version docs?
    v
    • 2
    • 2
  • c

    corneil

    11/10/2020, 9:55 AM
    Anyone from the kotlin documentation team? It is worthwhile for the users if you maintain separate documentation for 1.4.x and 1.3.x.
    d
    e
    • 3
    • 4
  • k

    Kenneth

    11/10/2020, 11:35 AM
    What is the default continuation indentation value in intellij?
    i
    • 2
    • 6
  • a

    Ayden

    11/13/2020, 12:29 AM
    Hi guys. Does Kotlin has any course website which similar like Laracast and VueMastery? It is focus driven on the particular item only.
    m
    a
    • 3
    • 2
  • d

    Draget

    11/13/2020, 8:52 PM
    In build.gradle.kts I can define:
    kotlin("jvm")
    Is this 'merely' a short hand form for
    id("org.jetbrains.kotlin.jvm" version "1.4.10"
    or does it do anything else?
    s
    j
    • 3
    • 4
Powered by Linen
Title
d

Draget

11/13/2020, 8:52 PM
In build.gradle.kts I can define:
kotlin("jvm")
Is this 'merely' a short hand form for
id("org.jetbrains.kotlin.jvm" version "1.4.10"
or does it do anything else?
Background: This syntax breaks dependency-scanning tool 'Renovate Bot', not recognizing the dependency anymore.
s

Saharath Kleips

11/13/2020, 9:02 PM
Our projects list it as:
kotlin("jvm") version "1.4.10"
And renovate picks it up fine. Would this work for you?
j

jbnizet

11/13/2020, 11:19 PM
@Draget to answer your question: yes, it’s just a shortcut.
d

Draget

11/13/2020, 11:27 PM
Interestingly renovate would ignore this Syntax @Saharath Kleips, we had 1.3.71 and if did not update. The moment we changed it to the id(...), it worked.
:blob-shrug: 1
View count: 1