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

    Vinicius Araujo

    10/12/2019, 2:12 PM
    Hi people, classes
    init
    blocks are not executed in casts right? Is there a way I could achieve it?
    d
    • 2
    • 5
  • m

    Marko Mitic

    10/12/2019, 8:02 PM
    I'm having an issue with Kotlin generics and generic java classes. I'm trying to write a function for a DI lib that will takes two Class instances, one of interface and one of class implementing the interface (akin to Dagger's
    @Binds
    ). So far, I can make it work with Kotlin types and even Java ones but it fails for generic Java types (like List<*> and ArrayList<*>). Is this limitation of generics system or am I doing something wrong? function:
    fun <C : I, I: Any> bind(clazz: Class<C>, iface: Class<I>)
    usage:
    bind(ArrayList::class.java, List::class.java) //kotlin types, works fine
    bind(java.util.ArrayList::class.java, java.util.List::class.java) // error: inferred type ArrayList<*> is not a subtype of List<*>
    m
    m
    t
    • 4
    • 13
  • f

    Felipe Álvarez

    10/12/2019, 8:52 PM
    Hey, I have a question related to data classes and Jackson deserialization. Let's suppose I have a
    data class
    as the class to be deserialized and I need to transform a JSON value into a custom object. For instance, a
    String
    value from JSON gets transformed into an
    enum
    value in my app, or color
    String
    into an
    Int
    . In Java, what I did was doing the transformation in the setter of the field. In Kotlin, it seems like Jackson uses the generated constructor for deserializing instead of getters and setters, so I end up having a
    InvalidFormatException
    because it cannot construct an instance of T type from some R type. BTW, I'm using
    KotlinModule
    in my
    ObjectParser
    Is there an elegant solution to this? Or this is not a good use case for data classes? A not so elegant solution I found was defining in my constructor a
    var
    of my "transformed" type and then a function
    set<jsonFieldName>
    that Jackson uses because it JSON field name and constructor field name don't match
    j
    • 2
    • 3
  • g

    groostav

    10/12/2019, 9:46 PM
    I've run into this kind of thing several times and it has often been the worst part of kotlin for me: the problem is when two types have the same short-name, eg:
    kotlin.Pair
    vs
    javafx.util.Pair
    . Can these inspections be updated to detect error messages like "expected List<ASDF> but was List<ASDF>"... oh, expected == actual, => fully qualify them => "expected List<com.yourcompany.ASDF> but was List<somebody.else.ASDF>" Maybe this can should be my first PR against the kotlin plugin repo?
    👍 1
    p
    • 2
    • 2
  • p

    pavi2410

    10/12/2019, 10:55 PM
    Why doesn't the vararg type checking work here? https://pl.kotl.in/opTRtUiQ7 (See
    mix
    variable)
    i
    • 2
    • 1
  • l

    LastExceed

    10/13/2019, 7:39 AM
    i have a function that takes 5 boolean parameters. i'd like to call it with all 10 possible value combinations where 3 of them are true and 2 are false. is there any fancy way to do this or do i just put 10 consecutive function calls ?
    p
    a
    k
    • 4
    • 9
  • k

    karelpeeters

    10/13/2019, 6:34 PM
    Is it possible to access the outer class instance for another instance of the current inner class? For example, I want to access
    other@Outer.x
    here but I can't figure out the syntax:
    class Outer(val x: Int) {
        inner class Inner {
            fun foo(other: Inner): Int = this@Outer.x + other@Outer.x
        }
    }
    j
    • 2
    • 2
  • p

    Paul Dhaliwal

    10/13/2019, 9:06 PM
    Is it possible to restrict creation of inner class objects to the outer class, so that other classes can’t do new innerObject = OuterClass.InnerClass()
    n
    a
    t
    • 4
    • 5
  • i

    Ifvwm

    10/14/2019, 5:53 AM
    sealed class Fix<F>
    data class MkFix<F> (val x: F<Fix<F>>): Fix<F>()
    this is possible?
    a
    m
    +2
    • 5
    • 10
  • a

    Andreas Unterweger

    10/14/2019, 11:18 AM
    hello, i have a question related to pojos and how to create them in kotlin with data classes. we have a bean which gets successively filled with data in different methods. this bean has other beans nested. if i use val in data classes this seems to become an issue since i cannot reassign vals. on the other hand i want to avoid nullability. so i want to set a default value and later overwrite it. is there a pattern in kotlin for that?
    s
    u
    c
    • 4
    • 9
  • b

    bitkid

    10/14/2019, 12:35 PM
    is there a ready to use library for reading kdocs from my code?
    m
    c
    • 3
    • 3
  • j

    jmfayard

    10/14/2019, 4:53 PM
    Here is a simple Kotlin question for which I don't have a simple answer Where should I put my extension functions?
    w
    g
    +5
    • 8
    • 11
  • a

    Ashutosh Panda

    10/14/2019, 5:13 PM
    var nullTest:Int?=null
    if(nullTest!=null)
        nullTest=1
    else
        nullTest=0
    println(nullTest)
    b
    • 2
    • 1
  • a

    Ashutosh Panda

    10/14/2019, 5:16 PM
    var nullTest:Int?=null
    nullTest?println("1"):println("0")
    r
    c
    +5
    • 8
    • 62
  • s

    standinga

    10/14/2019, 8:42 PM
    hey! what would be the best way to implement NaN with Long? I'm currently using Double.NaN to indicate invalid timestamps, but I'm leaning towards using milliseconds instead of seconds and using Long instead of Double. But I really like using NaN to indicate not set timestamp.
    c
    y
    • 3
    • 22
  • n

    nkiesel

    10/14/2019, 11:01 PM
    Is there a way to force the compiler to call an object method before this object is passed as a parameter to another method or returned to the caller? The concrete use case is a Builder for which
    applyBindings()
    (a normal method of that builder) must be called before it's passed on. We currently do that manually, but this of course leads to bugs where this call was forgotten.
    x
    • 2
    • 3
  • j

    jojo.lichtenberger

    10/15/2019, 7:32 AM
    Hi all, maybe someone is eager to help to build a versioned data store (currently for XML and JSON in a binary format, whereas the storage engine has been written from scratch). SirixDB shares unchanged database pages between snapshots and even versions data pages... https://sirix.io   the core has been written in Java but the REST-API is built with Vert.x and Kotlin (Coroutines) and I'd love to add Kotlin to other modules as it's so much more fun to write and read Kotlin code. I'd also love to provide a Kotlin DSL...
    r
    • 2
    • 1
  • p

    Prateek Grover

    10/15/2019, 7:39 AM
    which channel is dedicated for Q&A?
    k
    • 2
    • 4
  • m

    Maxim Kizub

    10/15/2019, 7:49 AM
    Hello everyone. I've created a feature request to add logical programming paradigm to Kotling. https://youtrack.jetbrains.com/issue/KT-34350?project=kt , can you comment on this proposal?
    x
    e
    • 3
    • 46
  • s

    Slackbot

    10/15/2019, 8:13 AM
    This message was deleted.
    k
    p
    • 3
    • 6
  • t

    thana

    10/15/2019, 9:28 AM
    when i have a property and method with the same name decalred on a class how can i get a reference to the property?
    ::propertyName
    resolves to the method, not the property
    r
    • 2
    • 4
  • s

    Stephan Schroeder

    10/15/2019, 11:01 AM
    Does any body know when/if a video of the SpringOne Platform 2019 talk “The State of Kotlin Support in Spring” will come online? https://springoneplatform.io/2019/sessions/the-state-of-kotlin-support-in-spring
    m
    e
    • 3
    • 3
  • a

    aballano

    10/15/2019, 12:42 PM
    Hi there, I'm trying to port some usages of AtomicInteger/Boolean/Reference to use github.com/Kotlin/kotlinx.atomicfu instead but apparently this is failing due to
    factory kotlinx.atomicfu.AtomicFU::atomic is used outside of constructor or class initialisation
    I'm just using them in local functions mainly, is this not permitted? if so, is there an alternative usage to do so? Thanks in advance! cc @elizarov
    e
    s
    • 3
    • 13
  • s

    Stephan Schroeder

    10/15/2019, 1:19 PM
    What is the point of the immutable collections lib (https://github.com/Kotlin/kotlinx.collections.immutable) given the the Kotlin collections are already read only? Just to make sure that other devs can’t cast it back to MutableCollection??
    a
    s
    +2
    • 5
    • 5
  • c

    Czar

    10/15/2019, 2:19 PM
    When implementing a Command and a Handler in Kotlin, e.g. in CQS or CQRS architecture, what's your preferred approach and why? 1️⃣
    class DoSomethingCommand : Command
    in DoSomethingCommand.kt and
    class DoSomethingCommandHandler : CommandHandler<DoSomethingCommand, R>
    in DoSomethingCommandHandler.kt 2️⃣ same as above but in one file, e.g. DoSomething.kt 3️⃣ Command handler is an inner class of the command:
    class DoSomethingCommand : Command { class DoSomethingCommandHandler : CommandHandler<DoSomethingCommand, R> }
    If that matters, command dispatcher is used, so handlers are only addressed directly in tests, otherwise it's
    commandInstance.execute()
    where
    fun Command.execute() = /* get command dispatcher from static context and dispatch the command */
    t
    • 2
    • 2
  • v

    veesus mikel heir

    10/15/2019, 4:33 PM
    shorthand for calling a super version of an overriden function
    f
    • 2
    • 1
  • t

    trevjones

    10/15/2019, 6:42 PM
    you might give the android lint tool a look. they analyze the uast, not sure if they parse it manually or grab it from the compiler impl though.
    👍 1
    g
    • 2
    • 1
  • m

    Mani

    10/15/2019, 8:20 PM
    Folks, I have a few queries on how to do this in Kotlin. 1. I have a bunch of urls as input. Need to iterate over them and download PDF's 2. Merge all these PDF's into one single PDF what are the relevant libraries for both downloading and merging? and is it advisable to do the merge on server? Worst case there can be 300, 400 urls at once. Also, since it is IO bound to download, will coroutines help in performance?
    :stackoverflow: 2
    m
    d
    +2
    • 5
    • 8
  • t

    taer

    10/15/2019, 9:20 PM
    Any best practices with inline classes and stringTemplates? I've making a pass through and ran into an interesting conversion gotcha. I have a String today, let's call it
    version
    I convert that into a wonderful inline class. I get all sorts of wonderful compile errors which I fix. However, this didn't pop up on the radar
    val versionTag = "ver-$version"
    As a String, this worked wonderfully. As an inline class, this ends up with the type name in the rendered String. I overrode
    toString()
    to handle this. I could have used the
    val
    from the inline class in the template as well. Either are valid solutions. I'm more worried about accidental usages in the future. Any thoughts as to making inline classes use in string templates a potential compile warning? Or something similar?
    ➕ 1
    l
    • 2
    • 2
  • r

    Robert Jaros

    10/15/2019, 9:58 PM
    A few months ago I've heard somewhere (kotlin forum? slack?) about a new tool for kotlin code generation (Kotlin Poet alternative). But I can't find the link. Anyone has an idea what project could it be?
    f
    • 2
    • 1
Powered by Linen
Title
r

Robert Jaros

10/15/2019, 9:58 PM
A few months ago I've heard somewhere (kotlin forum? slack?) about a new tool for kotlin code generation (Kotlin Poet alternative). But I can't find the link. Anyone has an idea what project could it be?
f

Foso

10/16/2019, 4:52 AM
Maybe #arrow-meta ?
View count: 5