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

    redrield

    06/14/2019, 8:02 PM
    I think I've found a compiler bug wrt inline classes, could someone confirm that my suspicion is correct? I'm trying to convert an existing units library that I use to use inline classes rather than boxing every entity. Once I'd completed, some of the tests for this project were failing with ClassCastException errors. I looked into it with a decompiler, and found that in one of the cases where I'd used the inline class, the decompiler shows a cast to Double from Length, and I assume that's what's causing the exception.

    https://0x0.st/zj-H.png▾

    The source version of that is this:
    operator fun contains(p: Translation2d) = p.x in x..(x + w) && p.y in y..(y + h)
    where all of the fields in use are Length, the inline class wrapping Double
    k
    s
    i
    • 4
    • 7
  • t

    Tuan Kiet

    06/15/2019, 1:27 AM
    e.g.
    () -> Unit
    is
    Function0<Unit>
    k
    • 2
    • 19
  • j

    Jacques Smuts

    06/15/2019, 9:00 AM
    Is there a high quality version of the :coroutine: icon somewhere I can use? Google has not been much help thus far.
    k
    • 2
    • 2
  • p

    pindab0ter

    06/15/2019, 4:17 PM
    Are there conventions for where to put extension functions and properties? I have a lot of calculated properties and functions for classes I can’t change because they’re part of a framework and such, spread over multiple sub-packages. Currently I have one big “Utilities.kt” file where they are all bunched together, separated into categories with only comments. This is file is starting to feel too big and bloated, but I can’t immediately think of a decent alternative. I don’t like the idea of cluttering my packages with lots and lots of tiny files with just a few extensions in htem. How do others deal with this?
    d
    a
    • 3
    • 7
  • f

    farzad

    06/15/2019, 7:19 PM
    https://stackoverflow.com/questions/56613415/a-pure-kotlin-way-of-implementing-publish-subscribe-pattern-which-is-type-aware
    t
    • 2
    • 4
  • s

    Sergio C.

    06/16/2019, 12:14 PM
    I'm trying to use the invoke function with objects that should be singletons, basically for having retrofit accept different base urls. If I call invoke("some url") in different places of the app how does that affect the singleton creation? Do I get the same object with the changed parameter , or is it creating a new object every time I call invoke?
    k
    • 2
    • 22
  • s

    Shawn

    06/16/2019, 4:12 PM
    val http200Status = object { val statusCode = 200; val description = "OK" }
    
    println("The status code is ${http200Status.statusCode}")
    👆 1
    👍 1
    w
    m
    +2
    • 5
    • 12
  • h

    Hullaballoonatic

    06/16/2019, 5:15 PM
    I don't suppose an abstract class has any way to define constructors or invoke operators of its inheritors?
    a
    l
    d
    • 4
    • 7
  • s

    Slackbot

    06/16/2019, 8:44 PM
    This message was deleted.
    k
    m
    • 3
    • 2
  • s

    Slackbot

    06/17/2019, 7:53 AM
    This message was deleted.
    t
    d
    • 3
    • 2
  • p

    pepe

    06/17/2019, 11:49 AM
    hey! I don't know if this makes much sense, but here it goes, imagine I have test utility method that among other things needs to check the type contained in an Either.Left, how would this be? is it even possible? is it just plain stupid trying to do so?
    fun testStuff([...], type: ?????) {
      [...]
      assert((foo as Either.Left).a is type)
      [...]
    }
    Should
    type
    be
    KClass
    or
    KType
    ?? I'm a bit lost
    s
    k
    m
    • 4
    • 6
  • y

    Yan Pujante

    06/17/2019, 1:16 PM
    does anybody know if the reference section on the kotlinlang website (https://kotlinlang.org/api/latest/jvm/stdlib/index.html) can be generated locally? Or another way to put it, is, is the code that generates these pages part of the kotlin project on github? Another project?
    m
    e
    • 3
    • 5
  • r

    robstoll

    06/17/2019, 1:40 PM
    Is it possible to define a function which expects a type which has implemented
    componentN()
    => https://kotlinlang.org/docs/reference/multi-declarations.html
    🤔 1
    b
    k
    +2
    • 5
    • 23
  • r

    rrader

    06/17/2019, 3:00 PM
    interface Some {
      fun calculate(str: String? = null)
    }
    class SomeImpl : Some {
      fun calculate(str: String? = null)
    }
    An overriding function is not allowed to specify default values for its parameters Why?
    l
    s
    • 3
    • 11
  • t

    Toddobryan

    06/17/2019, 3:30 PM
    I'm trying my hand at writing an annotation processor and, ideally, would like access to the parameters and default values in a class's constructor. However, I'm not sure this is possible, since annotation processors use Java models for the elements they're operating on and Java doesn't have a concept of default values. Is this possible? Are there Kotlin models that annotation processors can use that know more than the Java ones?
    t
    g
    • 3
    • 2
  • s

    Slackbot

    06/17/2019, 4:30 PM
    This message was deleted.
    s
    a
    • 3
    • 2
  • r

    robstoll

    06/17/2019, 4:47 PM
    shouldn't
    inline fun <reified T> foo() = T::class.qualifiedName
    be disallowed if
    inline fun <reified T> foo() = T::class
    is?
    s
    • 2
    • 13
  • s

    streetsofboston

    06/17/2019, 7:12 PM
    I’m curious, Is there a difference between:
    class Container<T>(val value: T)
    and
    class Container<T>(val value: T?)
    ? (note the extra
    ?
    after the
    T
    )?
    s
    p
    • 3
    • 22
  • r

    Robert

    06/17/2019, 7:43 PM
    I get this error from Gradle when building:
    Could not find org.jetbrains.kotlin:kotlin-stdlib-common:1.3.40-eap-107.
    while I use
    1.3.31-release-197
    . There's no such version in one of my build files as for
    1.3.40-eap-107
    , there's no version specified. It says it is from a dependency, but I don't see it and I don't understand how it makes sense.
    Required by:
        project :
        project : > project :KotlinBigInteger:bignum
        project : > project :KotlinBigInteger:bignum > org.jetbrains.kotlin:kotlin-test-common:1.3.31
    Any clue? Even stranger, when I build the main project (composite build) it produces this error. When I build the dependency only, it seems to work fine 😕
    • 1
    • 1
  • n

    Nezteb

    06/17/2019, 8:15 PM
    Anyone used any of these tools? https://github.com/google/error-prone https://github.com/typetools/checker-framework/ https://github.com/facebook/infer I’m looking to use them for some combined Java/Kotlin projects. The Kotlin code is pretty safe, but our Java code not so much 😕
    i
    r
    j
    • 4
    • 3
  • s

    sanmi

    06/18/2019, 1:43 AM
    Does anyone here know how to work with I/O(file) in Kotlin native. It appears I can't import java objects.
    l
    • 2
    • 1
  • i

    Ifvwm

    06/18/2019, 4:08 AM
    what's the difference between class and type?
    :stackoverflow: 3
    e
    • 2
    • 6
  • e

    egek

    06/18/2019, 2:50 PM
    Enum.values.random()?
    d
    s
    +2
    • 5
    • 4
  • r

    Rômero Ricardo

    06/18/2019, 4:12 PM
    Hi everyone, would you guys point me to the best source of information on Coroutines?
    r
    v
    l
    • 4
    • 3
  • r

    Ruckus

    06/18/2019, 5:05 PM
    Is it a known bug that this terminates at
    UInt.MAX_VALUE
    instead of
    UByte.MAX_VALUE
    ?
    fun main() {
        for (x in UByte.MIN_VALUE..UByte.MAX_VALUE) {
            println(x)
        }
    }
    s
    l
    • 3
    • 25
  • a

    ArtemHevorhian

    06/18/2019, 7:06 PM
    Thought about it too, but, from their website, "Kotlin/Native supports interoperability to use existing libraries directly from Kotlin/Native: C, Swift, and Objective-C frameworks", what I need instead is to use a C++ library, and I don't quite understand how to use Kotlin Native in this case, any suggestions?
    d
    d
    • 3
    • 6
  • z

    zak.taccardi

    06/18/2019, 7:53 PM
    where are
    typealias
    stored in Kotlin metadata?
    e
    • 2
    • 4
  • a

    Andrew Gazelka

    06/18/2019, 11:47 PM
    is there a reason why multiple
    fun main
    functions are allowed in the same package but not multiple
    fun main() = runBlocking { ... }
    g
    l
    • 3
    • 5
  • a

    Andrew Gazelka

    06/19/2019, 12:07 AM
    https://kotlinlang.org/docs/reference/operator-overloading.html any reason
    componentX()
    functions are not on this page?
    l
    • 2
    • 3
  • i

    Ifvwm

    06/19/2019, 1:52 AM
    interface Source<out T> { fun nextT(): T }
    s
    t
    +2
    • 5
    • 16
Powered by Linen
Title
i

Ifvwm

06/19/2019, 1:52 AM
interface Source<out T> { fun nextT(): T }
s

Shawn

06/19/2019, 1:56 AM
have you read the docs on variance?
i

Ifvwm

06/19/2019, 2:25 AM
https://kotlinlang.org/docs/reference/generics.html
yeah
I don't understand why there're two concepts called " Consumers." and "Producers,"
it doesn't make sense to me
t

treatmaster

06/19/2019, 2:52 AM
as I understand, it is a solution in Kotlin to solve generics issue in Java although Java has its own solution
i

Ifvwm

06/19/2019, 5:36 AM
<? extends E> which means ? is a subclass of E
<? super E> which means ? is a superclass of E
this is simple, but the annotate <in E> and <out E> are not easy to understand
s

SiebelsTim

06/19/2019, 6:09 AM
I think it's easier. If E is coming out of the class (ie return types only), it can be an out type. If it's coming into the class (ie parameters) its an in type
i

Ifvwm

06/19/2019, 6:32 AM
but they're related with the type inheritance
now return or pass in
not
s

SiebelsTim

06/19/2019, 7:28 AM
They are related. I think you should read the section "Declaration-site variance" in the above link. The names in and out are chosen to reflect what I said above.
m

Mike

06/19/2019, 12:02 PM
It's more about simplifying the implications of defining a generic as
extends
or
super
. When writing in Java, unless you're very familiar with typing constraints, and what it means to allow variance of types, you REALLY have to think/read about when to use
extends
vs
super
. Kotlin is trying to make it easier as one can easily determine if the generic is being used as an
in
or an
out
by reading the definition class, and can use the appropriate modifier. Make sense?
Side note: You can edit your most recent message using up-arrow. Can also edit older ones from more actions menu for a message.
View count: 7