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

    Jayden

    12/09/2019, 10:14 PM
    How do people normally name files that only contain extensions? 1. ViewExtensions.kt 2. ViewExt.kt 3. ?
    2️⃣ 3
    1️⃣ 9
    3️⃣ 7
    n
    a
    +2
    • 5
    • 7
  • g

    girafferson

    12/10/2019, 3:40 AM
    I'm not sure which channel this would be most relevant in. Does anyone know why my androidTest isn't building? I have
    android {
      defaultConfig {
        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner
    }}
    • 1
    • 2
  • j

    Joey

    12/10/2019, 5:36 AM
    Hi guys, what is the best way to return a
    List<String>
    from a coroutine? My current code is this one but its kinda slow and affects my UI in android
    fun fetchUsers(): List<String> {
        val heartbeatApi = HeartbeatApi()
        val users = runBlocking {
            withContext(Dispatchers.Default) {heartbeatApi.fetchUsers() }
        }
        return users
    }
    i
    e
    • 3
    • 4
  • a

    Ashutosh Panda

    12/10/2019, 7:48 AM
    class book(){
        var pages:Int=300
    }
    class puppy(b: book)
    {
        fun removePages():Int=b.pages-Random().nextInt(0,100)
    }
    
    fun book.getWeight():Double=pages*1.5
    val hamlet=book()
    val puppy=puppy(hamlet)
    fun book.CountPages(i:Int):Int=pages-i
    println("${hamlet.CountPages(20) } \n")
    println("${hamlet.getWeight()} \n")
    println("${puppy.removePages()+hamlet.CountPages(20)}")
    i
    m
    • 3
    • 7
  • h

    Hoanghun5

    12/10/2019, 12:50 PM
    Hello, I got an assignment to benchmark Java vs Kotlin. I was thinking I could benchmark Collections insert and remove speed such as ArrayList.add. Is it a good idea or does Kotlin just use internally Java colletions? If so, what else could I benchmark to show difference between Java and Kotlin?
    l
    r
    g
    • 4
    • 43
  • e

    eekboom

    12/10/2019, 2:07 PM
    While debugging: Is there a way to break on a property access? My workaround is to add a get() just for the sake of debugging while I need it :-(
    d
    • 2
    • 6
  • k

    Kris Wong

    12/10/2019, 4:53 PM
    how do I return/break to the next loop iteration
    loop@ for ((key, value) in jsonEvent.getObject("properties").content) {
        when (value) {
            is JsonArray -> {
            }
            is JsonPrimitive -> {
                value.booleanOrNull?.let {
                    event.properties[key] = it
                    return/break??
                }
            }
        }
    }
    b
    • 2
    • 2
  • p

    pniederw

    12/10/2019, 8:18 PM
    I wish
    when
    had better smart casts. I'm often hitting this case:
    open class Animal
    class Cat : Animal()
    class Dog : Animal()
    
    when (any) {
      is Cat, is Dog -> // I wish `any` had type `Animal` here, not `Any`
    }
    l
    a
    +4
    • 7
    • 41
  • s

    Slackbot

    12/10/2019, 10:02 PM
    This message was deleted.
    s
    • 2
    • 1
  • s

    ShootingStar

    12/11/2019, 12:41 AM
    In a Kotlin project with the gradle build, Is there a usecase to use a
    java-library
    plugin even though I already use kotlin gradle plugin?
    m
    p
    • 3
    • 3
  • a

    Aiden

    12/11/2019, 3:10 AM
    Can I know where can I learn more about NoSQL?
    r
    • 2
    • 1
  • k

    KyooSik Lee

    12/11/2019, 9:20 AM
    Hello I am pretty new to Functional Programming of Kotlin. I am currently using Reactor for my project It is difficult to work in streams because once the instances of the stream changes it form, I can’t use the instances before change. ex) • Flux<AClass> -> Flux<BClass> -> SomeFunction that needs instances of AClass If above situation happens, I had to find AClass instances again, so the stream would go like • Flux<AClass> -> Flux<BClass> -> Flux<AClass> which I think is redundant and DB-work-expensive So I came up with this Idea to store the value of AClass, and then use it later without getting back.
    fun someFunction(something: Foo): Mono<Foo> {
            var zoo: Foo = Foo();
    
            fooRepository.find()
                    .doOnNext { zoo = functionThatReturnsZoo() } // change the value of zoo
                    .flatMap { ... }
                    .flatMap { fooRepository.save(zoo) } // use zoo
        }
    Will this be functional too?
    b
    • 2
    • 9
  • x

    XQDD

    12/11/2019, 9:29 AM
    Why It becomes null when running in java
    • 1
    • 4
  • t

    trathschlag

    12/11/2019, 12:48 PM
    Nested, suspendable tailrec extension-functions (don't ask :)) seem to upset the compiler:
    fun test() {
        tailrec suspend fun Int.handle(): Int {
            return when {
                this <= 0 -> 0
                else -> (this - 1).handle()
            }
        }
    }
    =>
    :youtrack: 1
    i
    • 2
    • 3
  • t

    trathschlag

    12/11/2019, 12:48 PM
    e: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Failed to generate expression: KtNamedFunction
    File being compiled at position: [...]
    The root cause java.lang.AssertionError was thrown at: org.jetbrains.kotlin.codegen.context.MethodContext.getReceiverExpression(MethodContext.java:66)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:324)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.genStatement(ExpressionCodegen.java:407)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.generateBlock(ExpressionCodegen.java:1269)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.generateBlock(ExpressionCodegen.java:1214)
    	at org.jetbrains.kotlin.codegen.CodegenStatementVisitor.visitBlockExpression(CodegenStatementVisitor.java:56)
    	at org.jetbrains.kotlin.codegen.CodegenStatementVisitor.visitBlockExpression(CodegenStatementVisitor.java:22)
    	at org.jetbrains.kotlin.psi.KtBlockExpression.accept(KtBlockExpression.java:78)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:302)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.genStatement(ExpressionCodegen.java:407)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:364)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.returnExpression(ExpressionCodegen.java:1701)
    	at org.jetbrains.kotlin.codegen.FunctionGenerationStrategy$FunctionDefault.doGenerateBody(FunctionGenerationStrategy.java:64)
    	at org.jetbrains.kotlin.codegen.FunctionGenerationStrategy$CodegenBased.generateBody(FunctionGenerationStrategy.java:84)
    	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:666)
    	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:473)
    	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:260)
    	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:176)
    	at org.jetbrains.kotlin.codegen.FunctionCodegen.gen(FunctionCodegen.java:147)
    	at org.jetbrains.kotlin.codegen.MemberCodegen.genSimpleMember(MemberCodegen.java:197)
    	at org.jetbrains.kotlin.codegen.PackagePartCodegen.generateBody(PackagePartCodegen.java:95)
    	at org.jetbrains.kotlin.codegen.MemberCodegen.generate(MemberCodegen.java:129)
    	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateFile(PackageCodegenImpl.java:148)
    	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:68)
    	at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generatePackage(CodegenFactory.kt:96)
    	at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generateModule(CodegenFactory.kt:67)
    	at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.doGenerateFiles(KotlinCodegenFacade.java:47)
    	at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:39)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.kt:637)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:195)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:165)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:55)
    	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:84)
    	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:42)
    	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:104)
    	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:349)
    	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:105)
    	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:237)
    	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:88)
    	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:606)
    	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:99)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1645)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
    	at sun.rmi.transport.Transport$1.run(Transport.java:200)
    	at sun.rmi.transport.Transport$1.run(Transport.java:197)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
    	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
    	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    	at java.lang.Thread.run(Thread.java:748)
    Caused by: java.lang.AssertionError
    	at org.jetbrains.kotlin.codegen.context.MethodContext.getReceiverExpression(MethodContext.java:66)
    	at org.jetbrains.kotlin.codegen.TailRecursionCodegen.generateTailRecursion(TailRecursionCodegen.kt:62)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2511)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2476)
    	at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:41)
    	at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:13)
    	at org.jetbrains.kotlin.codegen.OperationStackValue.putSelector(StackValue.kt:79)
    	at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:122)
    	at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:115)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.putStackValue(ExpressionCodegen.java:384)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:365)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.lambda$generateWhenExpression$36(ExpressionCodegen.java:5028)
    	at org.jetbrains.kotlin.codegen.OperationStackValue.putSelector(StackValue.kt:79)
    	at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:122)
    	at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:115)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.putStackValue(ExpressionCodegen.java:384)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.lambda$visitReturnExpression$11(ExpressionCodegen.java:1612)
    	at org.jetbrains.kotlin.codegen.OperationStackValue.putSelector(StackValue.kt:79)
    	at org.jetbrains.kotlin.codegen.StackValueWithLeaveTask.putSelector(StackValue.kt:67)
    	at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:122)
    	at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:115)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.putStackValue(ExpressionCodegen.java:384)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:365)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.returnExpression(ExpressionCodegen.java:1701)
    	at org.jetbrains.kotlin.codegen.FunctionGenerationStrategy$FunctionDefault.doGenerateBody(FunctionGenerationStrategy.java:64)
    	at org.jetbrains.kotlin.codegen.coroutines.CoroutineCodegenForLambda$generateResumeImpl$1.doGenerateBody(CoroutineCodegen.kt:498)
    	at org.jetbrains.kotlin.codegen.FunctionGenerationStrategy$CodegenBased.generateBody(FunctionGenerationStrategy.java:84)
    	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:666)
    	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:473)
    	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:260)
    	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:176)
    	at org.jetbrains.kotlin.codegen.coroutines.CoroutineCodegenForLambda.generateResumeImpl(CoroutineCodegen.kt:464)
    	at org.jetbrains.kotlin.codegen.coroutines.CoroutineCodegenForLambda.generateClosureBody(CoroutineCodegen.kt:239)
    	at org.jetbrains.kotlin.codegen.ClosureCodegen.generateBody(ClosureCodegen.java:169)
    	at org.jetbrains.kotlin.codegen.coroutines.CoroutineCodegenForLambda.generateBody(CoroutineCodegen.kt:247)
    	at org.jetbrains.kotlin.codegen.MemberCodegen.generate(MemberCodegen.java:129)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.genClosure(ExpressionCodegen.java:1031)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.genClosure(ExpressionCodegen.java:1001)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.visitNamedFunction(ExpressionCodegen.java:973)
    	at org.jetbrains.kotlin.codegen.CodegenStatementVisitor.visitNamedFunction(CodegenStatementVisitor.java:46)
    	at org.jetbrains.kotlin.codegen.CodegenStatementVisitor.visitNamedFunction(CodegenStatementVisitor.java:22)
    	at org.jetbrains.kotlin.psi.KtNamedFunction.accept(KtNamedFunction.java:50)
    	at org.jetbrains.kotlin.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:302)
    	... 57 more
    s
    • 2
    • 3
  • b

    Brian Estrada

    12/11/2019, 1:32 PM
    I know this isn’t kotlin related but anyone here good with regex that can help me out?
    d
    r
    h
    • 4
    • 13
  • s

    silvio

    12/11/2019, 1:48 PM
    Why are Exceptions in Kotlin always unchecked? Wouldn't this lead to a lot of programming errors?
    a
    i
    • 3
    • 4
  • j

    John

    12/11/2019, 3:54 PM
    Has anyone found a way to pass a lambda in a Serializable object?
    j
    g
    • 3
    • 7
  • o

    Or Cohen

    12/11/2019, 4:26 PM
    Hi guys. I guess this is more of a Gradle related question but I’m just gonna post it here hoping for some sort of advice. Did anyone experience configuring (and working on) a monorepo containing multiple libraries? Lets assume that these libs can depend on one another AND and can also appear as dependencies in other projects (in other repos). This means that I wanna be able to: 1. Build the artifacts that are contained inside this mono repo in a way that’ll respect my dependencies. Assuming I have three libraries called A, B and C, while A depends on B and C is entirly independent, I wanna build both B and A in case there’s a change in B, but I don’t want C to be built) 2. Publish all artifacts that were changed during the build process to a local artifactory, later to be consumed by other components stored in different repositories I can share some more info on DM if needed, for example the tools used in my organisation with which I wanna achieve what I mentioned above. I encountered Gradle’s composite builds and multi-project builds but I’m still not quite sure about the differences and what fits better for my needs. Would appreciate any kind of help. Thanks in advance!
    c
    m
    • 3
    • 5
  • p

    Pacane

    12/11/2019, 10:20 PM
    I'm preparing the object to be added to the database in another layer where my transaction happens, and therefore I can't use
    MyEntity.new
    in that layer, otherwise it complains that there's no transaction context.
    t
    • 2
    • 1
  • j

    Joseph PH

    12/12/2019, 4:53 AM
    Hello, is it possible in Kotlin to do returns based on the configuration? For example,
    fun foo(useHttps: Boolean, conn: URLConnection): <Return type should either be HttpURLConnection/HttpURLsConnection> {
        // Logic here
        return URLConnection as HttpURLConnection/HttpURLsConnection // based on config?
    }
    j
    • 2
    • 2
  • t

    tony

    12/12/2019, 8:01 AM
    are there any tools available to compute the ABI of a Kotlin class? I am working on a gradle plugin that does some dependency analysis, and one thing I'd like to be able to do is tell users whether dependencies should be
    implementation
    or
    api
    . To do that, I need to know the ABI of a set of compiled .class files. I'd like a tool like ASM, but for Kotlin. I have found https://github.com/JetBrains/kotlin/tree/master/libraries/kotlinx-metadata/jvm, which is interesting, but it seems like it currently requires an actual KClass instance, when ideally I could just feed it a byte array (as in ASM)
    m
    • 2
    • 3
  • a

    Alexjok

    12/12/2019, 12:12 PM
    Hello, why when i try do something like this it's doesn't compile reason: Incompatible types: String and Class<T>
    class TypeClass<T>(
        private val returnResultAs: Class<T>
    ) {
    
        fun testCast(value: String): Result<Any, Exception> = when (returnResultAs) {
            is String -> Result.of { value }
            else -> Result.of { Gson().fromJson(value, returnResultAs) }
        }
    
    }
    But if i added
    returnResultAs as Any
    it works.
    class TypeClass<T>(
        private val returnResultAs: Class<T>
    ) {
    
        fun testCast(value: String): Result<Any, Exception> = when (returnResultAs as Any) {
            is String -> Result.of { value }
            else -> Result.of { Gson().fromJson(value, returnResultAs) }
        }
    
    }
    t
    • 2
    • 2
  • a

    Ashutosh Panda

    12/12/2019, 1:03 PM
    Hey can some one please explain me in type in generics
    e
    • 2
    • 2
  • a

    AdalPari

    12/12/2019, 2:49 PM
    Hi there! Are there any functional fun to iterate over a list and apply an operation to the current element with the previous one? It would be like a fold, but instead of accumulating the result, just applying it to each element. E.g:
    (1..9).fold("a", { last, current -> last + current })
    This just returns a123456789 but I actually need to create the following list: { "a1", "a12", "a123", "a1234", .. } I would be more like a map but knowing previous element:
    (1..9).map { "$previousElement$it" }
    s
    k
    h
    • 4
    • 12
  • k

    Kris Wong

    12/12/2019, 8:14 PM
    IDEA all of a sudden seems to be really confused about my Kotlin/JVM project. it won't build or run it anymore. when I try it just does nothing.
    h
    j
    • 3
    • 8
  • k

    Kroppeb

    12/12/2019, 9:17 PM
    The
    ::gcd
    is referencing the
    Iterable<Int>.gcd()
    instead of
    gcd(Int, Int)
    . Swapping
    ::gcd
    to
    ::helpers.gcd
    gives
    Unresolved reference: helpers
    but renaming the function to something else and then back to
    gcd
    will swap it to
    ::helpers.gcd
    which is marked red with
    Internal Error occured while analyzing this expression
    . How should I fix?
    Untitled
    r
    • 2
    • 5
  • m

    Mehdi

    12/13/2019, 12:51 AM
    Does anybody know any useful library for invoking SOAP web services in Kotlin?
    😱 4
    😬 2
    s
    w
    m
    • 4
    • 6
  • b

    basher

    12/13/2019, 2:19 AM
    Any good blog posts about refactoring using Kotlin delegation or using Kotlin delegation that's not about properties? As an iOS developer, this is something I haven't quite wrapped my head around in terms of when I should use this tool compared to something else
    m
    • 2
    • 4
  • a

    Andreas Jost

    12/13/2019, 9:15 AM
    If I have to filter a list, is it always better (performance-wise) to convert it to a flow first or did I misunderstand something?
    s
    m
    • 3
    • 6
Powered by Linen
Title
a

Andreas Jost

12/13/2019, 9:15 AM
If I have to filter a list, is it always better (performance-wise) to convert it to a flow first or did I misunderstand something?
s

streetsofboston

12/13/2019, 9:40 AM
No, unless you really need a Flow, don't convert it to a Flow. Just keep it as a list and call
filter
on it. For large lists and if you call many operators on the list, you may want to convert it to a
Sequence
.
Also, avoid optimizing (early) if you don't see or experience a performance issue. 😀
💯 3
a

Andreas Jost

12/13/2019, 9:46 AM
Thanks, but flows/sequences would make sense if I had a larger list of data entities and want to map it to a list of domain entities, and might also filter afterwards, right? I will look up the difference between flow and sequence.
s

streetsofboston

12/13/2019, 10:03 AM
Flow is a (cold) stream of data. You'd need a Coroutine to collect the data emitted by a Flow. A Sequence is a 'lazy' view on a collection (list). No need for Coroutines.
➕ 1
a

Andreas Jost

12/13/2019, 10:05 AM
Understood, great explanation, thank you!
m

Matteo Mirk

12/24/2019, 9:36 AM
If it’s not a huge list, just call
list.filter {}
and be fine. I support what Anton said: don’t optimize prematurely, only if you experience a slow execution.
View count: 2