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

    Mustafa

    10/16/2019, 7:40 AM
    My manager is making me re-write my kotlin api's into Java. Oh My God. #help
    :goberserk: 1
    👎 2
    🤦‍♂️🏽 6
    t
    m
    +5
    • 8
    • 12
  • s

    Steph Carter

    10/16/2019, 3:13 PM
    Are the Kotlin playgrounds down for anyone else? https://try.kotlinlang.org https://play.kotlinlang.org
    c
    s
    +3
    • 6
    • 10
  • e

    Emil Orvik Kollstrøm

    10/16/2019, 8:26 PM
    What is the simplest to use XML deserialization library for Kotlin? Love Klaxon for JSON, but it does not support XML
    a
    s
    • 3
    • 4
  • p

    poohbar

    10/16/2019, 9:57 PM
    I have two files named
    Extensions.kt
    in the same package but in two different modules. Maven compiles everything successfully but when running it it suddenly can't find some of the extension methods. Is that a bug?
    j
    g
    • 3
    • 2
  • p

    poohbar

    10/16/2019, 10:28 PM
    Specifically, I get
    java.lang.NoSuchMethodError
    . Pretty odd that it fails at runtime.
    g
    • 2
    • 1
  • s

    Steve Young

    10/17/2019, 3:20 AM
    @Animesh Sahu are you using okhttp engine? It has pingInterval setting https://square.github.io/okhttp/3.x/okhttp/okhttp3/OkHttpClient.Builder.html
    a
    • 2
    • 1
  • k

    kushalp

    10/17/2019, 1:05 PM
    Is anyone using avro4k to manage their serialisation to Avro for Kafka? How are you getting it to work with the
    KafkaAvroDeserializer
    ? I'm getting the following error:
    Unsupported Avro type. Supported types are null, Boolean, Integer, Long, Float, Double, String, byte[] and IndexedRecord
    https://github.com/sksamuel/avro4k
    r
    m
    s
    • 4
    • 21
  • a

    Ashutosh Panda

    10/17/2019, 3:53 PM
    var numbers=arrayOf(
        11,
        12,
        13,
        14,
        15
    )
    
    var integer:MutableList<Int>=mutableListof()
            for(x in 0 until (numbers.size-1)) {
                integer[x]=numbers[x]
            }
    for(element in integer) println("$element")
    a
    g
    +2
    • 5
    • 14
  • s

    Sam Schilling

    10/17/2019, 5:25 PM
    Is there any guidelines on what order to put things in a class? E.g., properties at top and methods below, private before public, where to put companion objects or nested classes/enums, etc
    r
    r
    • 3
    • 4
  • e

    elaborate tissue

    10/17/2019, 6:43 PM
    Is it true KClass is automatically converted to a Class when being passed to an annotation? wondering because I'm trying to use this annot https://github.com/google/auto/tree/master/service and it doesn't work when using it from kotlin
    :yes: 1
    s
    • 2
    • 3
  • m

    Michael

    10/17/2019, 6:52 PM
    How do I type a lambda if they compiler is giving me an “`Overload resolution ambiguity`” ? I’m doing a thing like
    .processor { it }
    where processor can take a
    Function
    or a Functional Interface.
    r
    • 2
    • 3
  • m

    Marc Knaup

    10/18/2019, 10:44 AM
    Can I suppress a function’s
    DeprecationLevel.HIDDEN
    and use it anyway? 🙂
    t
    e
    • 3
    • 3
  • p

    Paul Dhaliwal

    10/18/2019, 8:49 PM
    Is it possible to maker a mapping extension function which will convert the Type of an object. For example, I have a Results sealed class and within it different data classes for different results:
    sealed class Result<out T : Any?> {
        data class Success<out T : Any>(val data: T) : Result<T>()
        data class Unauthorized(val exception: Exception) : Result<Nothing>()
        data class Timeout(val exception: Exception) : Result<Nothing>()
        data class Error(val exception: Exception) : Result<Nothing>()
    }
    and I’d like to make a mapping extension function like so Result<EntityModel>.toDomain(DomainModel) which would output Result<DomainModel>. So if the object was Success<UserEntityModel> it would return Success<UserDomainModel>
    k
    k
    j
    • 4
    • 8
  • j

    jmfayard

    10/19/2019, 8:54 AM
    Kotlin is not synonym with Android! Kotlin is a great solution for backend programming, building REST/GraphQL/… API with spring, spring boot, http4k, ktor, vertx, … Kotlin can be used for fullstack frontend/backend, for command-line apps, multiplatform iOS-Android, browser extensions, data science, desktop apps with TornadoFX. Did I forget something important? Please comment
    m
    s
    +3
    • 6
    • 11
  • j

    Joan Colmenero

    10/19/2019, 3:42 PM
    Having this
    sealed class
    ?
    sealed class ResultWrapper<T> {
    data class Success<T>(val data: T) : ResultWrapper<T>()
    data class Unauthorized(val exception: UnauthorizedException) : ResultWrapper<Nothing>()
    data class Forbidden(val exception: ForbiddenException) : ResultWrapper<Nothing>()
    data class Network(val exception: NetworkException) : ResultWrapper<Nothing>()
    data class NotFound(val exception: NotFoundException) : ResultWrapper<Nothing>()
    data class BadRequest(val exception: BadRequestException) : ResultWrapper<Nothing>()
    data class Error(val exception: Exception) : ResultWrapper<Nothing>()
    }
    Then I have a method that returns a
    ResultWrapper<T>
    but I'm only able to return the
    ResultWrapper.Success(it)
    how can I return the other ones?
    d
    k
    • 3
    • 4
  • a

    Ashutosh Panda

    10/20/2019, 9:52 AM
    import kotlin.arrayOf as arrayOf1
    var i=0
    var number:Array<Int> = arrayOf(11,12,13,14,15)
    var integer: MutableList<Int> = mutableListOf(5) {0}
    for(x in 0 until 5) {
        
        integer[x]=number[x]
        
    }
    println(integer[2])
    This is program and the error is
    -error: none of the following functions can be called with the arguments supplied:
    @SinceKotlin @InlineOnly public inline fun <T> mutableListOf(): MutableList<Int> defined in kotlin.collections
    public fun <T> mutableListOf(vararg elements: Int): MutableList<Int> defined in kotlin.collections
    var integer: MutableList<Int> = mutableListOf(5) {0}-
    a
    • 2
    • 1
  • a

    Ashutosh Panda

    10/20/2019, 9:57 AM
    import kotlin.arrayOf as arrayOf1
    var i=0
    var number:Array<Int> = arrayOf(11,12,13,14,15)
    var integer: MutableList<Int>(5) {0}
    for(x in 0 until 5) {
        
        integer[x]=number[x]
        
    }
    println(integer[2])
    this is the changed one and error is
    `
    error: property getter or setter expected
    var integer: MutableList<Int>(5) {0}`
    k
    k
    • 3
    • 20
  • j

    John

    10/20/2019, 7:10 PM
    Anyone else getting their IDEA really slow on simple checks in kotlin? Pasting 20 lines takes about 5 seconds to index all the variables
    :yes: 3
    m
    w
    +3
    • 6
    • 10
  • a

    Arkadii Ivanov

    10/20/2019, 8:32 PM
    What is the preferred naming style for a factory function? Is it better to start names from uppercase or lowercase letters? I have found the following in Kotlin Coding Conventions:
    Exception: factory functions used to create instances of classes can have the same name as the class being created
    But what is the recommended style?
    n
    k
    • 3
    • 3
  • s

    Sergio C.

    10/20/2019, 8:49 PM
    why can't I call this function from the code?
    object Extensions {
    
        inline fun <reified T : Any> SharedPreferences.getObject(key: String): T? {
            return Gson().fromJson<T>(getString(key, null), T::class.java)
        }
    }
    can't call mySharedPrefs.getObject<Object>(KEY)
    🤔 1
    a
    j
    • 3
    • 7
  • j

    Joan Colmenero

    10/21/2019, 7:23 AM
    Is there any channel to put a question of stackoverflow that I've added a bounty (400) to check if someone can help me out? Is about drag and drop. (Android)
    t
    c
    • 3
    • 3
  • g

    Gyuhyeon

    10/21/2019, 8:44 AM
    New to kotlin, and I've been trying to figure out what the best practices are for null checks in kotlin. The suggestions are all over the place, and they rarely consider usages other than a single liner. I'd like some opinions on the following:
    if (someObj != null) {
        val someOtherLogic = repository.selectOne(someObj.field)
        someOtherLogic.doThis()
        someOtherLogic.doThat()
    } else {
        someService.someBusinessLogic()
    }
    apparently, checking null with
    if
    statements is not the "kotlin way". [citation needed] from what I've gathered, the "kotlin way" is the following.
    someObj?.also {
        val someOtherLogic = repository.selectOne(someObj.field)
        someOtherLogic.doThis()
        someOtherLogic.doThat()
    } ?: run {
        someService.someBusinessLogic()
    }
    but honestly, this looks like some serious code-smell to me. Maybe it's because I come from java, but if what the code is trying to achieve is
    do some business logic based on the isExists state of an object and do something else if it doesn't exist
    , using
    ?.also{} ?: run{}
    seems way worse than an explicit easy to read
    if / else
    . Any input would be appreciated.
    w
    r
    +3
    • 6
    • 8
  • g

    Georgi Naumov

    10/21/2019, 11:32 AM
    Hello. Probably the question is extremely stupid. I apologize but how I can convert object which is already parsed and has gotten from JSON array back to JSON? I want to get the JSON representation for that object only . Any hints would be appreciated. :(
    s
    • 2
    • 1
  • m

    Martin Jinoch

    10/21/2019, 11:33 AM
    Jackson ObjectMapper has method writeValueAsString(object)
    👍 1
    g
    s
    • 3
    • 2
  • d

    Daan

    10/21/2019, 3:47 PM
    is there a kotlin roadmap somewhere? I'd like to have at least a vague idea of where most effort is being spent right now and also what's coming (or might be coming) in the future
    w
    j
    k
    • 4
    • 4
  • h

    Harry

    10/21/2019, 9:50 PM
    You can change delay at line 13 or the number of consumers at line 12, but the pattern of output is identical
    k
    • 2
    • 1
  • b

    bodiam

    10/22/2019, 12:18 AM
    Hi all, I'm trying to refactor some code, and I feel like I'm almost there, but I can't find the last missing bit. I have the following code:
    MemberTbl.select {
        MemberTbl.member_id eq "200"
    }.first().also {
       assertThat(it[MemberTbl.id]).isEqualTo("200")
    }
    But, I'd like to refactor it to something like:
    MemberTbl.findByMemberId("200")
    with the help of an extension function, since this code is duplicated quite a lot. What I have so far is this:
    private fun MemberTbl.findByMemberId(s: String, row: ResultRow.() -> Unit) = this.select { member_id eq s }.first().also { row (it)  }
    So that my end result will look like this:
    MemberTbl.findByMemberId("200") {
         assertThat(it[MemberTbl.id]).isEqualTo("200")
    }
    But that won't, since the
    it
    in the assertEquals is no longer the closure passed in. How can I fix this?
    w
    • 2
    • 10
  • p

    PabloCasia

    10/22/2019, 6:06 AM
    Hi all, I've two infix functions
    infix fun Any.fun1(block: () -> Unit) = block.invoke()
    infix fun Any.fun2(block: () -> Unit) = block.invoke()
    And I'm trying to use variables from first fun on second fun, something like:
    fun1 { val item1 = "" } fun2 { val item2 = item1 }
    But item1 scope is only fun1 Any suggestions? Aware from declare as a lateinit var outside the functions
    j
    k
    s
    • 4
    • 6
  • p

    Paul Woitaschek

    10/22/2019, 7:36 AM
    Are there a recommended practice about when to use an if and when to use a when expression?
    e
    s
    +2
    • 5
    • 6
  • g

    gavvvr

    10/22/2019, 11:23 AM
    Hi guys. Do you have an experience with setting up sonarqube on Kotlin projects? I decided to add Sonar to Jenkins pipeline of my Spring Boot Kotlin app. Do not know why, but Sonar does not index Kotlin files 😐 . Same thing happens to other kotlin-examples maven projects. But for simplest hello world apps it works. Asked a question here with steps to reproduce: https://stackoverflow.com/questions/58500406 Any ideas why Sonar ignores Kotlin sources?
    w
    m
    • 3
    • 3
Powered by Linen
Title
g

gavvvr

10/22/2019, 11:23 AM
Hi guys. Do you have an experience with setting up sonarqube on Kotlin projects? I decided to add Sonar to Jenkins pipeline of my Spring Boot Kotlin app. Do not know why, but Sonar does not index Kotlin files 😐 . Same thing happens to other kotlin-examples maven projects. But for simplest hello world apps it works. Asked a question here with steps to reproduce: https://stackoverflow.com/questions/58500406 Any ideas why Sonar ignores Kotlin sources?
w

wasyl

10/22/2019, 11:26 AM
Did you make sure to install Kotlin plugin?
g

gavvvr

10/22/2019, 2:39 PM
@wasyl Kotlin plugin is installed by default, made sure bu checking content of docker image and inside Sonar admin panel GUI. For some very simple Kotlin projects Sonar works, for some does not
m

Mike

10/22/2019, 2:59 PM
Sounds like a project config issue, then...
View count: 11