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
announcements
  • p

    pugnator

    01/26/2019, 8:00 AM
    Hello! I cant good speck and write English but I need Your help. Exist methods for DoubleClick?
    🤦‍♂️ 3
    😂 2
    :google: 1
    h
    • 2
    • 2
  • a

    Andrew Gazelka

    01/26/2019, 4:18 PM
    what...
    ⛏️ 1
    🐛 1
    s
    • 2
    • 3
  • h

    hyukchan

    01/26/2019, 8:35 PM
    object A : Table(name = "a_table") { var b = date("b_column") }
    g
    • 2
    • 1
  • h

    hyukchan

    01/26/2019, 8:41 PM
    Not helping me 😕
    r
    p
    g
    • 4
    • 11
  • d

    Dico

    01/26/2019, 9:39 PM
    I ran into a situation where I am importing a top-property with a * import, and a type with the same name explicitly. I wanted to invoke a static method from the type, which resolved to a call on the property that I imported. At first I thought this is definitely a bug, but I realized that it is probably a subjective matter. There are two rules at play: * In Kotlin, properties and local variables take precedence over types/companion objects when resolving a function-with-receiver call. * Also, explicit imports take precedence over symbols imported with a
    *
    import. The reality is that the first rule seems to take priority over the second. I think it should be the other way around. What do you think?
    r
    • 2
    • 22
  • a

    Andrew Gazelka

    01/27/2019, 3:02 AM
    any idea why I am getting this?
    override fun <SubsystemStateCondition>getConditionValue(): SubsystemStateCondition {
            return state
        }
    interface Condition {
        fun <T> getConditionValue(): T
    }
    n
    d
    p
    • 4
    • 3
  • p

    pajatopmr

    01/27/2019, 8:19 AM
    Given a sealed class Foo and an instance of
    val someClass: KClass<out Foo>
    is it possible for
    someClass.objectInstance
    to be null? I think the answer is yes but I am struggling to come up with a way to make a test for such a thing. The documentation for objectInstance says, ” …if this class is not an object declaration” so my question really boils down to: how do I define a class that is not an object declaration? And the corollary, can I define a member of a sealed class that is not an object declaration. If you’re inclined to reply, please do so in a thread. Thanks. fwiw, my brain hurts just trying to grok this.
    p
    • 2
    • 7
  • d

    Dalinar

    01/27/2019, 12:02 PM
    what class are `object`s ?
    m
    • 2
    • 8
  • h

    hyukchan

    01/27/2019, 1:14 PM
    I'm losing connection to the DB using Jetbrains Exposed... And it's not trying to reconnect by himself. Anyone can help me ?
    h
    • 2
    • 2
  • h

    hyukchan

    01/27/2019, 1:33 PM
    Is there any way to marshal Kotlin list of pairs as json object with each pair being key, value ?
    k
    • 2
    • 1
  • d

    Davide Giuseppe Farella

    01/27/2019, 2:00 PM
    well, that happens only if the companion got the
    private
    modifier, ok with nothing(
    public
    ),
    internal
    or even
    protected
    d
    • 2
    • 7
  • t

    Tasos Stamadianos

    01/27/2019, 6:53 PM
    Hi all, I've been getting an interesting error when my app runs for an extended period of time:
    17:10:33.977 [main] ERROR bees.stream.MessageStream - [MessageStream.kt:42] || - Message deserialization failed.
    kotlin.reflect.full.IllegalCallableAccessException: java.lang.IllegalAccessException: class kotlin.reflect.jvm.internal.calls.CallerImpl$Constructor cannot access a member of class bees.stream.MessageStream$SystemMessage with modifiers "public"
            at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:224)
            at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflect_api(KCallableImpl.kt:152)
            at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:110)
            at com.squareup.moshi.kotlin.reflect.KotlinJsonAdapter.fromJson(KotlinJsonAdapter.kt:104)
            at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:137)
            at com.squareup.moshi.JsonAdapter.fromJson(JsonAdapter.java:41)
            at bees.stream.MessageStream.onMessages(MessageStream.kt:39)
            at bees.stream.kafka.KafkaConsumerProducerStream.start(KafkaProducerConsumerStream.kt:64)
            at bees.BeesKt.main(bees.kt:65)
    Caused by: java.lang.IllegalAccessException: class kotlin.reflect.jvm.internal.calls.CallerImpl$Constructor cannot access a member of class bees.stream.MessageStream$SystemMessage with modifiers "public"
            at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361)
            at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:591)
            at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
            at kotlin.reflect.jvm.internal.calls.CallerImpl$Constructor.call(CallerImpl.kt:41)
            at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:106)
            ... 8 common frames omitted
    17:10:33.989 [main] DEBUG bees.stream.MessageStream - [MessageStream.kt:83] || - Completed message processing. Returning 0 responses.
    I have a Moshi instance whose job it is to do this deserialization. The class it wants to create is:
    private data class SystemMessage(val command: String, val sessionId: UUID, val commandId: UUID, val data: Any)
    . This is private to the class within the module. This only happens when the app is running for longer periods, if I restart and try again it works fine. When I search "java cannot access a member of a class with modifiers public", I get results which indicate that the class cannot be instantiated since it's private to its enclosing class. However, this doesn't explain why it works for some time if I restart the app. I've tried with JVM 8 and JVM 11, same error on both. This was built with Kotlin 1.3.10, but I'm going to try 1.3.20 now. Any help would be greatly appreciated 🙂
    r
    d
    d
    • 4
    • 20
  • m

    Marc Knaup

    01/27/2019, 7:45 PM
    is there a workaround for https://youtrack.jetbrains.com/issue/KT-28418?
    java.lang.IncompatibleClassChangeError: com.github.fluidsonic.fluid.json.ListJSONDecoderCodec and com.github.fluidsonic.fluid.json.ListJSONDecoderCodec$$special$$inlined$create$1 disagree on InnerClasses attribute
    • 1
    • 1
  • a

    Andrew Gazelka

    01/27/2019, 8:37 PM
    is it bad practice to start interfaces with
    I
    ?
    n
    d
    +5
    • 8
    • 24
  • n

    Nikky

    01/27/2019, 9:03 PM
    did:
    org.jetbrains.kotlinx:kotlinx-html-jvm:0.6.10
    get removed from the kotlinx repo ?
    i
    • 2
    • 2
  • p

    Paul N

    01/28/2019, 9:21 AM
    I;m working through the ray tracer challenge book, which is a test based tutorial on how to code a ray tracer. At the start of the book they define a class known as a Tuple, which models a position or a vector. A simplified version is this class Tuple(val x: Double, val y: Double, val z: Double, val w: Double) There's a lot of overloaded constructors and operator overloads but the basic structure is pretty simple, 4 doubles, x,y,z, and w. In the second chapter they introduce the concept of a Color, which is in essence also a Tuple, with red,green and blue instead of x,y and z. Is there any way I can somehow base Color on Tuple, with RGB mapping to xyz ?I guess I could delegate to a Tuple rather than somehow extend it, but that that sounds a bit clunky.
    g
    d
    • 3
    • 15
  • a

    Anton

    01/28/2019, 1:37 PM
    Have a general question about kotlin plugin for intellij. Does exist some IDE action for navigation to kotlin extension function (or just function)? Currently I use [option+command+O] for navigation to symbol, but search result polluted with java method names (especially for such common names as fold, reduce etc)
    h
    • 2
    • 2
  • a

    aerialist

    01/28/2019, 3:10 PM
    Hi All, I want to create extension function (like
    run
    https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/run.html) which returns nothing (
    Unit
    ) (see code block).
    towards
    function purpose: run
    block()
    in scope of
    T
    . And if
    block()
    returns some result - it must be ignored. Kotlin-Dev Team, could you please recommend better name? And do you have plans to add same extension to language? Thank you in advance.
    -.rb
    d
    n
    a
    • 4
    • 15
  • m

    Marcin Wisniowski

    01/28/2019, 6:37 PM
    Hello, could someone tell me what is the difference between these two ways of synchronization and why would I use one over the other? I noticed it's impossible to call suspending functions inside a synchronized block but it's fine with the other way, why is that?
    -.kt
    h
    g
    • 3
    • 6
  • x

    xenoterracide

    01/28/2019, 7:19 PM
    where can I find information/listing on options like jvm-default?
    j
    • 2
    • 1
  • j

    jlleitschuh

    01/28/2019, 7:26 PM
    I have a fairly large multi-project (~ 70 projects) Kotlin and Gradle Kotlin DSL based project. I just updated to Kotlin
    1.3.20
    and now I'm getting
    java.lang.OutOfMemoryError: Metaspace
    exceptions from the Koltin compiler. I'm also using the
    kotlin.parallel.tasks.in.project=true
    flag. Is this a known issue & is there a workaround?
    🤩 1
    l
    g
    • 3
    • 4
  • r

    Robert

    01/28/2019, 7:38 PM
    What is the correct way to compare Byte to Int?
    if (myByte.compareTo(myInt) == 0)
    ?
    if (myByte.toInt() == myInt)
    ?
    if (myByte == myInt.toByte())
    ? Something else? Or can I force implicit conversion somehow, as I have a lot of these comparisons?
    j
    h
    • 3
    • 5
  • d

    Dominaezzz

    01/28/2019, 8:17 PM
    Anyone out there do code gen? I want to generate kotlin (multiplatform) code from an xml schema and need guidance on project structure.
    n
    • 2
    • 66
  • s

    snowe

    01/28/2019, 11:14 PM
    Does anyone know why updating from kotlin 1.2 to 1.3 would result in springboottests throwing these errors? And how to fix it.
    Caused by: java.lang.IllegalStateException: Resource not found in classpath: kotlin/coroutines/coroutines.kotlin_builtins
    I believe it may have something to do with the fact that we have a gradle build with a maven parent pom using gradle’s
    implementation(platform())
    ability.
    c
    • 2
    • 9
  • a

    Andrew Gazelka

    01/29/2019, 12:04 AM
    is there a standard of when to use higher order functions vs interfaces with one method?
    s
    g
    • 3
    • 7
  • s

    snowe

    01/29/2019, 6:52 AM
    I previously had this,
    fun Suite.mapsTo(expected: String) {
            val testObject by memoized<Any>()
            it("test value") {
                pp(testObject)
                outContent shouldRenderLike expected
            }
        }
    
        fun testObject(obj: Any?) {
            val testObject by memoized { obj }
        }
        
        describe("tiny object should") {
            context("render a single field") {
                testObject(TinyObject(1))
                mapsTo(
                    """
                    TinyObject(
                      int = 1
                    )
                    """
                )
            }
        }
    but I find it very messy, and I can't use an infix....
    a
    • 2
    • 7
  • t

    thana

    01/29/2019, 7:17 AM
    Is somethink like type safe heterogenous containers even possible with kotlin? http://www.informit.com/articles/article.aspx?p=2861454&amp;seqNum=8
    n
    • 2
    • 8
  • j

    jdemeulenaere

    01/29/2019, 1:43 PM
    Is there still no Gradle plugin to generate Kotlin code based on (any platform) Kotlin code (similar to java annotation processors), or any kind of plans/KEEP for metaprogramming in Kotlin ? Something like official compiler API to manipulate (or even read only) the AST would be really nice.
    c
    k
    l
    • 4
    • 7
  • d

    Dalinar

    01/29/2019, 2:12 PM
    how does kotlin generate hashcodes for data classes?
    c
    • 2
    • 1
  • d

    Dalinar

    01/29/2019, 2:12 PM
    it uses the hashcodes of the vals?
    r
    • 2
    • 1
Powered by Linen
Title
d

Dalinar

01/29/2019, 2:12 PM
it uses the hashcodes of the vals?
r

robin

01/29/2019, 2:38 PM
Yeah. You can decompile the generated bytecode for a data class and see that a data class defined like this:
data class Person(val string: String, val int: Int, val any: Any)
has a generated hashcode function that boils down to something like this this:
override fun hashCode(): Int {
        return ((string?.hashCode() ?: 0) * 31 + int * 31) + (any?.hashCode() ?: 0)
    }
✔️ 1
View count: 5