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

    Slackbot

    07/02/2021, 9:15 PM
    This message was deleted.
    👏 3
    m
    1 reply · 2 participants
  • s

    standinga

    07/03/2021, 12:52 AM
    hello lovely people:) I would like to extend static method of Java (Android) Color class, something like:
    fun Color.parseNullableColor(colorString: String?): Int? {
        val colorString = colorString ?: return null
        try {
            return Color.parseColor(colorString)
        } catch (e: IllegalArgumentException) {
            return null
        }
    }
    Seems it’s not possible? https://stackoverflow.com/questions/28210188/static-extension-methods-in-kotlin Thanks!
    e
    3 replies · 2 participants
  • t

    TwoClocks

    07/03/2021, 9:24 PM
    I think I found a bug in kotlin 1.5.20, but I can't get a simple repro case. I have a
    if
    that's being skipped, even though it evluates to
    true
    in the debugger. I think it has to do w/ nullable types. There is a if statement above the one being skipped that under certin conditions will assign a instance to a nullable type. Then the second if statement checks some other conditions on that nullable type... but it looks like the compiler is just skipping the entire evluation of the second
    if
    e
    7 replies · 2 participants
  • l

    lesincs

    07/04/2021, 9:31 AM
    In addition to
    mutableList.add(0,element),
    are there any other APIs to insert an element to the head of a
    mutablelist
    ?
    mutableList.add(0,element)
    is ok, but not as expressive. 🤔
    c
    r
    +2
    6 replies · 5 participants
  • s

    Slackbot

    07/04/2021, 1:30 PM
    This message was deleted.
    j
    m
    2 replies · 3 participants
  • m

    MaHDi

    07/04/2021, 3:21 PM
    Hi everyone. How can we access the fileName of our main function in Kotlin? for example, suppose we have a file Example.kt that has a main function in it declared outside any class. I want to access the fileName and the package that Example.kt is in. Thanks for your help.
    b
    2 replies · 2 participants
  • s

    Sam Garfinkel

    07/04/2021, 4:48 PM
    Is Swing the only remaining way to build truly cross-platform Desktop UIs (without building OS-specific distributables)?
    r
    a
    +4
    12 replies · 7 participants
  • j

    Jason5lee

    07/05/2021, 2:52 AM
    I have a dependency which has no nullable annotation. Can I add these annotations externally in my project? I expect something similar to
    .d.ts
    .
    g
    e
    +1
    4 replies · 4 participants
  • s

    Slackbot

    07/05/2021, 3:37 AM
    This message was deleted.
    g
    d
    +1
    6 replies · 4 participants
  • e

    Emile Baccaini

    07/05/2021, 1:17 PM
    hi everyone, thanks for the invitation! I was wondering what is the best place to find jobs here?
    n
    b
    3 replies · 3 participants
  • c

    Charlie L

    07/06/2021, 1:09 AM
    Any pointers on how to bulk fix
    Suspend function '..' should be called only from a coroutine or another suspend function
    using IntellIJ? I can’t find any corresponding inspection in Code Cleanup, though I swear I automated this before…
    k
    1 reply · 2 participants
  • n

    Noushad Chullian

    07/06/2021, 6:15 AM
    HI Everyone...Can I ask Questions here??
    :yes: 6
    m
    1 reply · 2 participants
  • s

    Slackbot

    07/06/2021, 6:28 AM
    This message was deleted.
    i
    n
    +2
    8 replies · 5 participants
  • p

    pmatthews

    07/06/2021, 9:45 AM
    Can anyone suggest the best way to get the current data class’ package name in the constructor as a default value?
    d
    4 replies · 2 participants
  • g

    Guilherme Gomes Correia

    07/06/2021, 9:57 AM
    Hey guys! Are there any Mapper Frameworks (like MapStruct) that works very well with Kotlin? Any suggestions?
    s
    2 replies · 2 participants
  • u

    user

    07/06/2021, 5:42 PM
    message has been deleted
    n
    r
    2 replies · 2 participants
  • j

    james

    07/07/2021, 4:31 AM
    can anyone advise if something fundamental changed with how
    equals()
    works or how
    kotlin.test.Assertions
    might handle
    RuntimeExceptions
    between Kotlin v1.3.62 and v1.5.20? I have a unit test that is more than a year old which started failing when I updated the version of Kotlin. details: I have a custom exception class, MyException:
    internal class MyException(cause: Throwable) : RuntimeException(cause)
    I then have some code which simply catches any errors and logs:
    } catch (e: Exception) {
            myLogger.logException(MyException(e))
        }
    Now inside the unit test, we want to confirm that we’re catching exceptions, transforming them to our type, and logging. So the exception is thrown and then log is checked as such:
    val exception = RuntimeException("some failure!")
    ...
    ...
    loggedExceptions.latest() shouldBeInstanceOf MyException::class
    (loggedExceptions.latest() as MyException).cause shouldBeEqualTo exception
    that final line now fails with the following:
    java.lang.AssertionError: Expected <java.lang.RuntimeException: some failure!>, actual <java.lang.RuntimeException: some failure!>.
    to reiterate, nothing about this unit test (or the class which it is testing) has changed in over a year. I can’t explain what could be happening here? would greatly appreciate it if someone could shine any light on this. see attached the version diff:
    s
    1 reply · 2 participants
  • e

    elect

    07/07/2021, 7:56 AM
    where am I supposed to pass specific kotlin compiler arguments, such as
    -Xadd-modules=
    , if running via Idea?
    h
    1 reply · 2 participants
  • u

    user

    07/07/2021, 11:33 AM
    Adding Volume to the Kotlin Identity Kotlin isn’t just a programming language, and it’s not just a language for Android development. It’s a whole ecosystem for creating various projects, from mobile apps and websites to data science. It’s an active, friendly community, with hundreds of online and offline events happening all around the world. Despite its fairly long history, Kotlin has […]
    e
    m
    2 replies · 2 participants
  • j

    Jurriaan Mous

    07/07/2021, 1:11 PM
    Maybe it is time to update the logo of this Slack workspace :kotlin: (+ the emoji) to the new one :kotlinnew:?
    a
    1 reply · 2 participants
  • u

    user

    07/07/2021, 4:08 PM
    message has been deleted
    c
    1 reply · 1 participant
  • i

    Irene Serrano

    07/07/2021, 7:48 PM
    Hello All, I'm having trouble converting the following java code into kotlin. Can I get your input? The Java code:
    if (hiddenView.getVisibility() == View.VISIBLE) {
         TransitionManager.beginDelayedTransition(cardView, new AutoTransition());
         hiddenView.setVisibility(View.GONE);
                       
    }
    My code:
    if (hiddenView.isVisible) {
         TransitionManager.beginDelayedTransition(cardView, AutoTransition())
         hiddenView.visibility = it.GONE
    }
    a
    l
    3 replies · 3 participants
  • m

    maarten ha

    07/07/2021, 9:58 PM
    Is it possible to get and set audio volume controls with kotlin for mac, windows and/or linux. I've seen a couple of open source project but don't really understand how they work. The goal is to make an application to remotely fine control my pc(windows) en laptop(mac book) volume, this will be linked to my phone(android) and Ipad(ios). The lateral isn't the big issue but the volume control on the os is. Let me know some suggestions or projects to check out, any help would be welcome. Preferably in Kotlin 😉:kotlin-intensifies:
    :blob-shrug: 1
    c
    2 replies · 2 participants
  • m

    Martin Brehovsky

    07/08/2021, 10:16 PM
    A quick questions on generics. Is it possible to enforce non-nullable type from a nullable type? Something like this:
    class Foo<T: Any?> {
      
        abstract fun returnValue(): T
        abstract fun returnValueAsNonNullable(): T!! // this doesn't work 
    
    }
    The problem is I need to define the T type as either nullable or non-nullable, but I'm trying to bridge semantics of reactive streams, which are always non-nullable and represent
    null
    by empty stream state, and futures which are possibly nullable. However I need to differentiate between a nullable and non-nullable future, therefore decide whether to allow the reactive stream to return empty value (as null) or fail.
    m
    s
    +2
    8 replies · 5 participants
  • c

    Cyril Scetbon

    07/09/2021, 4:41 AM
    Hey, I’m trying to call https://github.com/jesperfj/force-rest-api/blob/b1f6330d49211f639b903225926d081fcece487e/src/main/java/com/force/api/ResourceRepresentation.java#L36-L38 from kotlin but I get the error
    expecting an element
    val res = api.getSObject("Account", "0015000000VALDtAAP").as(Account::class)
                                                              ^
    It seems there is an internal kotlin function/keyword 
    as
     that prevents me from calling that function on my class. For instance the class String  can get the same error
    >>> val x = "10"
    >>> x.f1("ola")
    error: unresolved reference: f1
    x.f1("ola")
      ^
    >>> x.as("ola")
    error: expecting an element
    x.as("ola")
      ^
    I should get the same error but nope, any idea what’s going on ?
    k
    s
    +1
    4 replies · 4 participants
  • j

    Justin Tullgren

    07/09/2021, 2:43 PM
    Hello, I am trying to migrate to kotlin 1.5 and use the new value class but I cant find the
    @JvmInline
    annotation. Do i need to add a certain dependency?
    1 reply · 1 participant
  • w

    William Reed

    07/09/2021, 7:40 PM
    is there anyway to annotate a method such that there is a warning if it is called from kotlin code, but nothing happens if it is called from java? There are several edge cases where I want to expose a different API to java consumers for the legacy portion of my code base, but I don’t want to encourage the usage of it from the newer kotlin code
    m
    y
    4 replies · 3 participants
  • a

    aniruddha dhamal

    07/10/2021, 12:41 AM
    Hi, Have question related to Generics.
    interface DataProvider<T> {
        fun provideData(t:T): Data
    }
    
    class TaxDataProvider: DataProvider<Tax> {
        override fun provideData(t: Tax): Data {
            return Data()
        }
    }
    
    class Provider {
        fun register(dataProvider: DataProvider<*>) {
            dataProvider.provideData(Tax())  //Not able to call this. Getting error: Type mismatch Required Nothing. Found Tax
        }
    }
    Is there any way to achieve this? I wanted to keep register method to accept type of DataProvider not specific type (TaxDataProvider).
    d
    n
    +1
    11 replies · 4 participants
  • g

    Gopal S Akshintala

    07/11/2021, 5:16 AM
    Hi, are there any existing solutions to auto-generate a Kotlin data class from Java class parameter (like
    Pojo.class
    ) or any other way?
    m
    u
    3 replies · 3 participants
  • s

    SirNapkin1334

    07/11/2021, 6:17 AM
    is there a convention for a placeholder to denote a section of code that won't be reached? for example, after a loop with a return in it that always returns. i've been using
    TODO()
    and a short explanation of why it's unreachable, but is there a "better" way of doing it?
    r
    f
    +2
    6 replies · 5 participants
Powered by Linen
Title
s

SirNapkin1334

07/11/2021, 6:17 AM
is there a convention for a placeholder to denote a section of code that won't be reached? for example, after a loop with a return in it that always returns. i've been using
TODO()
and a short explanation of why it's unreachable, but is there a "better" way of doing it?
r

rajesh

07/11/2021, 6:33 AM
Comments are your best friends to describe code
s

SirNapkin1334

07/11/2021, 6:36 AM
i mean, that the section is unreachable, but the compiler can't know that, so is there any convention for what to do, asides from throwing an error that you know will never happen so the compiler knows the function can return?
f

Fleshgrinder

07/11/2021, 6:46 AM
I asked once for an
unreachable
like we have it in Rust and the consensus with the Kotlin devs was that
error("unreachable: description")
is good enough. Unlike Rust Kotlin doesn't need it to compile and adding it was perceived as adding unnecessary complexity.
e

ephemient

07/11/2021, 7:12 AM
https://github.com/Kotlin/KEEP/issues/204
there are ways in which the Kotlin language could be evolved to make use of
unreachable()
, but they don't exist now (and the plan for exhaustive-when doesn't use it)
s

Sourabh Rawat

07/11/2021, 8:42 AM
I just throw IllegalStateExcpetion.
View count: 5