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

    GarouDan

    06/12/2020, 10:57 PM
    Hi, Where in your opinion is the best place to publish an
    open source kotlin mpp library
    ?
    maven central
    ,
    bintray
    ,
    jcenter
    , other?
    a
    l
    +2
    14 replies · 5 participants
  • h

    Hamza

    06/13/2020, 5:54 AM
    how are we supposed to represent decimals with big decimal? am I missing something?
    g
    a
    +2
    6 replies · 5 participants
  • v

    Victor Harlan Lacson

    06/13/2020, 6:57 AM
    Hello, Anyone can share how to publish kotlin multiplatform. Currently my implementation focused on jvm target and i want to publish it on bintray. And im using gradle kotlin dsl No success atm. Any help would be appreciated
    1 reply · 1 participant
  • d

    Dom

    06/13/2020, 6:30 PM
    Is it possible to pass
    this
    as a parameter to an interface delegate?
    interface A
    
    class B(private val c : C) : A
    
    class C : A by B(this)
    produces an error saying that "`this` is not defined in this context". Is there a workaround for this?
    s
    s
    +1
    4 replies · 4 participants
  • s

    Samyak Jain

    06/14/2020, 2:32 PM
    Hi which channel to follow for asking discussions about core kotlin source?
    t
    1 reply · 2 participants
  • m

    mwong

    06/15/2020, 11:02 AM
    Is there a way to have a sealed class define an abstract method and have the parameter smart casted to the subclass? Something like this:
    sealed class ItemType {
    	data class Section(name: String) : ItemType() {
    		override fun areContentsTheSame(other: ItemType.Section) = name == other.name
    	}
    	
    	data class Item(value: Long): ItemType() {
    		override fun areContentsTheSame(other: ItemType.Item) = value == other.value
    	}
    	
    	abstract fun areContentsTheSame(other: ItemType): Boolean
    }
    m
    4 replies · 2 participants
  • r

    Ryan

    06/15/2020, 12:40 PM
    Anyone know why kotlin isn’t picking up my User interface on LoginUserV1?
    m
    a
    9 replies · 3 participants
  • r

    Ryan

    06/15/2020, 12:41 PM
    maybe my user interface is bad?
    c
    2 replies · 2 participants
  • a

    Antoine Gagnon

    06/15/2020, 2:01 PM
    Hey everyone, I’ve having some issues with type inference. I have a function similar to the one in SharedPreferences that retrieves a String, and if it doesn’t find it, it’ll return the default parameter that’s nullable
    fun getString(key: String?, default: String?): String?
    The issue is that I’m trying to make it so that the compiler can tell if the default is null or not, and make the return type null or not. I’ve tried doing this:
    fun <T:String?>getString(key: String?, default: T): T
    But if the default is value
    null
    , the inffered type becomes
    Nothing?
    instead of
    String?
    Any idea on how to do this properly?
    l
    1 reply · 2 participants
  • r

    Ryan

    06/15/2020, 2:49 PM
    whats the keyword to have intefaces generate default stubs?
    r
    1 reply · 2 participants
  • d

    dead.fish

    06/15/2020, 3:05 PM
    Is this a bug that
    Collections.singletonList()
    is seen as a
    MutableList
    in Kotlin?
    🤔 3
    j
    e
    9 replies · 3 participants
  • e

    ec

    06/15/2020, 4:35 PM
    Is there a tool that converts my kotlin classes or java pojos to fillable html form? Currently I’m traversing class fields via reflection produce something like json-schema, which I use to generate a form on frontend. Existing pojo->json schema/avro etc tools not seems to be working reliably
    v
    1 reply · 2 participants
  • r

    Ryan

    06/15/2020, 9:53 PM
    mapOf(“key” to ()->Unit = {})
    s
    e
    +1
    9 replies · 4 participants
  • g

    GarouDan

    06/15/2020, 10:32 PM
    Hi, What is the easiest way to convert from
    SortedSet<String>
    to pure array
    String[]
    in Kotlin?
    s
    13 replies · 2 participants
  • p

    parth

    06/15/2020, 10:50 PM
    is it possible to have a custom property delegate that can provide a nullable value to a nullable property and a non-nullable value to a non-nullable field? aka:
    class Foo {
        val one : String by someProperty()
        val two : String? by someProperty()
    }
    ….and if so, what would be the signature of 
    operator fun getValue(…)
    ? I guess I could do 
    val two : String? by someOptionalProperty()
     to make the type signature easier, but that feels like I’m giving up, y’know?
    b
    a
    3 replies · 3 participants
  • w

    william

    06/16/2020, 1:54 AM
    Any suggestions for the right approach to generics here?
    import androidx.lifecycle.MutableLiveData
    
    class ClearableLiveData<T> : MutableLiveData<Clearable<T>>() {
        fun clear(t: T) {
            super.postValue(Clearable.Clear)
            super.postValue(Clearable.Value(t))
        }
    }
    
    sealed class Clearable<T> {
        object Clear: Clearable<Any>()
        data class Value<T>(val t: T): Clearable<T>()
    }
    The first call to
    super.postValue
    gives a type mismatch
    m
    k
    10 replies · 3 participants
  • g

    GarouDan

    06/16/2020, 3:19 AM
    Hello everyone, Can we do something like this in
    Kotlin Common
    instead of JVM?
    class MyClass<MyGeneric> {
        lateinit var myGenericClass: Class<MyGeneric>
    
        fun init() {
            myGenericClass =
                (javaClass.genericSuperclass as ParameterizedType)
                    .actualTypeArguments[0] as Class<MyGeneric>
        }
    }
    Get the generic type?
    r
    e
    5 replies · 3 participants
  • p

    Patrick

    06/16/2020, 7:56 AM
    Is there an easy way to do String normalization in pure Kotlin (no JVM dependencies)? I am looking for something similar (or better identical) to the JavaScript String.prototype.normalize function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize
    h
    9 replies · 2 participants
  • c

    CLOVIS

    06/16/2020, 8:12 AM
    Does anyone know if inline classes will be stable in 1.4?
    h
    s
    +1
    4 replies · 4 participants
  • s

    spand

    06/16/2020, 9:23 AM
    Any reason one cannot
    continue
    from within an inline function like
    for (i in (1..2)) {
        run  { continue }  
    }
    Should it not be the same as
    return
    ?
    h
    k
    +1
    4 replies · 4 participants
  • r

    Ryan

    06/16/2020, 11:45 AM
    when are generics going to be fixed?
    z
    j
    +1
    20 replies · 4 participants
  • m

    Maria Khalusova

    06/16/2020, 12:16 PM
    Hi folks, We are happy to share with you the Kotlin Spark API we’ve been working on: https://github.com/JetBrains/kotlin-spark-api.  Right now it is in beta stage and we need your feedback before we create a pull request to the official Apache Spark repository.  Why Kotlin Spark API? While you can use Kotlin with the existing Apache Spark Java API, Kotlin Spark API significantly improves the developer experience. For instance, this API allows you to use such Kotlin features as data classes and lambda expressions.  On top of that Kotlin Spark API adds some helpful extension functions. Use
    withCached
    to perform arbitrary transformations on a Dataset without it being recalculated, and don’t worry about your Dataset unpersisting at the end. Kotlin Spark API also allows you to have unnamed tuples that you can call with
    c()
    function that takes a variable number of arguments. You can add these to one another like in Python. Check out the Quick Start Guide to quickly set up all the needed dependencies using Maven or Gradle: https://github.com/JetBrains/kotlin-spark-api/blob/master/docs/quick-start-guide.md Check out some code examples to get an idea of what the API looks like: https://github.com/JetBrains/kotlin-spark-api/tree/master/examples/src/main/kotlin/org/jetbrains/spark/api/examples Try it and share your feedback with us either in #kotlin-spark, or via GitHub issues: https://github.com/JetBrains/kotlin-spark-api/issues.
    🔥 5
    🎉 16
    a
    1 reply · 2 participants
  • a

    Aaron Stacy

    06/16/2020, 4:22 PM
    Hi all, I'm trying to figure out why I can't reference an outer class's
    this
    for a lambda with a receiver. Here's a code snippet https://pl.kotl.in/GtgL1DMFc . Based on https://kotlinlang.org/docs/reference/this-expressions.html it seems like I should be able to reference the outer
    this
    via a label, so why can't the compiler resolve the
    @A
    reference? Thanks!
    d
    r
    4 replies · 3 participants
  • i

    iex

    06/16/2020, 5:47 PM
    with JUnit (4), Is there an uncomplicated way to test that a callback was called (ideally without mockito or any other 3d party)? E.g. in Swift you can declare an "expectation" at the beginning of the test, call
    waitForExpectations(timeout: 5, handler: *nil*)
    at the end, and in the callback
    expectation.fullfill()
    to have the test wait for the callback
    c
    e
    +2
    13 replies · 5 participants
  • j

    JoseF

    06/17/2020, 9:26 AM
    Hi, is there any way to have
    required
    parameters in
    KotlinDsl
    that are validated at compilation time?
    i
    g
    3 replies · 3 participants
  • m

    Mananpoddarm

    06/17/2020, 2:26 PM
    A = (char *) malloc(sizeof(char) * 6);
    Hi everyone, could someone help me with what is the alternative of malloc in kotlin? I would like to convert above in kotlin
    s
    m
    +1
    3 replies · 4 participants
  • a

    Ananiya

    06/17/2020, 4:39 PM
    Kotlin is the best funny addictive and simple languages I ever seen I ❤️ :kotlin: but Who does invented the kotlin (the people) not a company (JetBrains)
    🤔 1
    m
    s
    +1
    9 replies · 4 participants
  • v

    vaskir

    06/17/2020, 4:50 PM
    this appears every time I'm setting a breakpoint. Why? Can I turn it off? I just don't see the difference.
    a
    j
    4 replies · 3 participants
  • b

    Brendan Weinstein

    06/17/2020, 5:18 PM
    Is there an advantage to doing something like
    val Strings.empty by lazy { "" }
    and using
    Strings.empty
    where ever an empty string is needed in code (eg
    val a = b ?: Strings.empty
    )?
    s
    s
    8 replies · 3 participants
  • s

    streetsofboston

    06/17/2020, 7:54 PM
    Rewriting
    d1
    like this makes it a proper singleton (type === value) and your error goes away.
    object d1 : java.util.Date() { // d1 is of type d1, which is a sub-type of java.util.Data
        val test = 5
    }
    Still, why would a local val allows access to
    test
    but a top/global one not…. not sure 🙂
    z
    3 replies · 2 participants
Powered by Linen
Title
s

streetsofboston

06/17/2020, 7:54 PM
Rewriting
d1
like this makes it a proper singleton (type === value) and your error goes away.
object d1 : java.util.Date() { // d1 is of type d1, which is a sub-type of java.util.Data
    val test = 5
}
Still, why would a local val allows access to
test
but a top/global one not…. not sure 🙂
z

Zach Klippenstein (he/him) [MOD]

06/17/2020, 9:13 PM
I think it might be a JVM/bytecode thing. This code works too:
class Test {
  public void test() {
    new Date() {
      public String fooBar() {
        return "foo bar";
      }
    }.fooBar();
  }
}
But there’s no way to do that at a higher level since java requires explicit types.
s

streetsofboston

06/17/2020, 9:39 PM
Thanks JVM!!! 😛
View count: 2