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

    Patrick Jackson

    05/23/2019, 3:36 PM
    It seems every reference in Kotlin either extends Any, or implements kotlin.Function. if there is a generic field is there any way to get the type of the function so it can be executed? Appears type data is erased and impossible to do anything like
    is () -> Unit
    k
    r
    s
    • 4
    • 6
  • r

    Rak

    05/23/2019, 4:03 PM
    I need to throw an exception using reflection, any examples? The exception type is a string
    d
    • 2
    • 1
  • n

    nickk

    05/23/2019, 4:39 PM
    Is it possible to do something like this? I want to avoid switching on each potential type. Does type erasure make it impossible?
    data class DataDriver<T>(val valueCalculator: (T) -> Int)
    
    val dataDriver = listOf(
            DataDriver<T1>( ::calcValue1),
            DataDriver<T2>( ::calcValue2)
    )
    
    // Using reified worked here
    private inline fun <reified T> query(isSubmitted: Boolean): List<T> { 
    	return realm.where<T>().equalTo("submitted", isSubmitted).find()
    }
    
    fun calcValue1(item: T1) -> Int {
    	return 42
    }
    
    // But what about here?
    // Apply transforms to get a list of calculated items,
    // calling the proper query and calculator based on the type.
    // Without resorting to type checks for each type.
    // IS THIS POSSIBLE?
    dataDriver.map {
    	query()  // type inference fails here
    		.map(::valueCalculator) 
    }
    k
    d
    r
    • 4
    • 18
  • l

    Lou Morda

    05/23/2019, 4:43 PM
    Do data classes need unit tests if we know they only have a primary constructor and no methods? data class(val id: String, val firstName: String, val lastName: String)
    r
    e
    +2
    • 5
    • 5
  • l

    LeoColman

    05/24/2019, 1:35 AM
    Currently, when refactoring a package that has the common name ommited, the refactor changes the package name to not include the common name, and this doesn't seem right. No compiler warning, #detekt doesn't get it, and IntelliJ doesn't do it's job correctly
    ➕ 1
    d
    • 2
    • 2
  • i

    Iaroslav Postovalov

    05/24/2019, 6:38 AM
    Why doesn't Kotlin contain default value for type parameters?
    class Foo<T = Any>(val t: T = Any())
    ...
    Foo()
    g
    b
    +2
    • 5
    • 9
  • e

    elect

    05/24/2019, 11:04 AM
    if I type
    override fun equals(other: Any?): Boolean = when(other) {
            this -> true
    will
    other
    checked using == or === ?
    m
    j
    +2
    • 5
    • 12
  • j

    Joao Birk

    05/24/2019, 1:11 PM
    Hi there, have a QQ, let me know if this is not the right channel. By calling <string>.startsWith("$$"), I see some IllegalArgumentException reports coming from that: Caused by: java.lang.IllegalArgumentException: at kotlin.text.StringsKt__StringsJVMKt.b (StringsKt__StringsJVMKt.java) at kotlin.text.StringsKt__StringsJVMKt.startsWith$default (StringsKt__StringsJVMKt.java:195) I checked the code and dont see anything related and why this might be throwing such exception. Unfortunately I dont have a sample string that is causing the issue.
    m
    k
    i
    • 4
    • 19
  • n

    nickk

    05/24/2019, 1:28 PM
    Is there a way to iterate over a List of reified types?
    d
    • 2
    • 5
  • u

    user

    05/24/2019, 2:03 PM
    message has been deleted
    👍 1
    e
    • 1
    • 1
  • n

    Nikky

    05/24/2019, 4:26 PM
    i am looking for a commandline parsing library that supports sub commands and is not hardcoded to println() everything idally i want to pass a custom logger to it, but the frameworks i looked at so far did not have the capability for that also subcommands and not killing the app on failure would be nice (looking at clickt) does anyone know which commandline parsers might cover at least some of those features ?
    k
    • 2
    • 13
  • g

    GarouDan

    05/24/2019, 6:13 PM
    I’m trying to use kotlin
    1.3.40-eap-32
    but my build is failing with something like:
    Could not resolve org.jetbrains.kotlin:kotlin-test-common:1.3.40-eap-32.
             > Could not get resource '<https://dl.bintray.com/kotlin/kotlin-eap/org/jetbrains/kotlin/kotlin-test-common/1.3.40-eap-32/kotlin-test-common-1.3.40-eap-32.module>'.
                > Could not GET '<https://dl.bintray.com/kotlin/kotlin-eap/org/jetbrains/kotlin/kotlin-test-common/1.3.40-eap-32/kotlin-test-common-1.3.40-eap-32.module>'.
                   > <http://dl.bintray.com|dl.bintray.com>
    Is this the expected behavior for now? Until it is not released?
    👍 1
    i
    • 2
    • 6
  • d

    daggerok

    05/25/2019, 5:13 PM
    Hi guys! Can you please help me properly setup maven pom.xml to execute JUnit 5 Jupiter tests in mixed Java + Kotlin project. Can someone of you provide me worked example? PS: I have also posted similar questions on JUnit GitHub and StackOverflow: - https://github.com/junit-team/junit5/issues/1899 - https://stackoverflow.com/questions/56306835/pom-xml-maven-configuration-to-run-junit-4-junit-5-jupiter-tests-in-mixed-java?noredirect=1#comment99224282_56306835 Thanks! --- Regards, Maksim
    • 1
    • 1
  • d

    daggerok

    05/25/2019, 9:33 PM
    Does anyone knows if it’s possible somehow configure maven pom.xml to allow java tests to be recognized from
    src/test/kotlin
    folder? I prepared an example you can quickly clone and verify:
    git clone <https://github.com/daggerok/mixed-kotlin-java-jupiter-tests> testme ; cd $_ ; mvn test
    here kotlin tests could be recognized from both
    stc/test/kotlin
    as well as from
    src/test/java
    , but java test classes are visible only from
    src/test/java
    Let me know if you know how to tell maven in it’s pom.xml project build configuration also recognize java tests classes from
    src/test/kotlin
    directory too Thanks
    s
    • 2
    • 1
  • m

    Matej Drobnič

    05/26/2019, 8:04 AM
    Is not being able to call extension class methods from another class (https://youtrack.jetbrains.com/issue/KT-24290) design choice or shortcoming of the compiler? It makes class methods that extend
    CoroutineScope
    (needed by convention) quite awkward to call.
    ➕ 2
    l
    p
    • 3
    • 6
  • s

    stanislav

    05/26/2019, 12:52 PM
    hi! What kind of compiler architecture does Kotlin have?
    l
    • 2
    • 3
  • m

    mingkangpan

    05/26/2019, 2:54 PM
    @SqlMarker
    object SQLBuilder {
        fun query(init: SqlSelectBuilder.() -> Unit): SqlSelectBuilder {
            val builder = SqlSelectBuilder()
            builder.init()
            return builder
        }
    }
    I have this, but somehow the compiler still let me do this eventough I marked it with DSLMarker
    val query = SQLBuilder.query {
            
            query { 
                
            }
    what am I doing wrong? 😞
    k
    • 2
    • 22
  • l

    Lulu

    05/26/2019, 9:19 PM
    Is an enum or a sealed class better for a large number of entries (i.e. emojis) ? I tried a sealed class but the IDE marks them as unused (they're part of the API) and it's very laggy
    d
    l
    • 3
    • 2
  • f

    fangzhzh

    05/27/2019, 3:05 AM
    Hi, is there a rxkotlin related channel?
    g
    • 2
    • 2
  • l

    Lorin

    05/27/2019, 7:32 AM
    Hi all, I have a question about kotlin (v1.3.31) reflection.
    fun main(args: Array<String>) {
        fun <P1, P2, R> ((P1, P2) -> R).partial(p1: P1): (P2) -> R = { p2: P2 -> this(p1, p2) }
    
        fun regexMatch(re: Regex, s: String): Boolean = re.containsMatchIn(s)
        val match = ::regexMatch.partial(Regex("^123"))
    
        println(match("12345"))
        println(match("123xx"))
        println(match("2345"))
        println(match)
        println(match.reflect()!!.run {
            "(${parameters.map { it.type }.joinToString()}) -> $returnType" })
    }
    The output (the signature of
    match
    ) is
    (P2) -> R
    . Is there any way to infer the actual correct signature which should be
    (String) -> Boolean
    ?
    d
    • 2
    • 4
  • j

    Jan

    05/27/2019, 10:24 AM
    is there a generic constraint to enforce equals operator?
    d
    • 2
    • 2
  • a

    Adrián

    05/27/2019, 1:40 PM
    Hi, I noticed a common problem when modeling using Sealed classes and Data classes. In my projects, this approach is too common and we noticed a boilerplate problem when we need to modify the content using the copy method of data classes. Currently, Kotlin does not provide a way to restrict the Sealed classes implementations to Data classes, so if you want to use copy method, you need to check for all concrete data classes and it is a pain in the ass. Imagine the next scenario:
    sealed class MyModel {
            abstract val name: String
            abstract val title: String
    }
    data class Model1(
                override val name: String,
                override val title: String,
    ) : MyModel()
    ...
    data class Model100(
                override val name: String,
                override val title: String,
    ) : MyModel()
    If you want to modify the title, for example, adding the environment where you are running your code could be similar to:
    fun MyModel.addEnvironmentToTitle(env: String) = when (this) {
    	is MyModel1 -> copy(title = title + env)
    	... -> // Same boilerplate here
           is MyModel100 -> copy(title = title + env)
    }
    It is a simple example but you could have more complex code and it becomes unmanageable. Does anyone know if we will have in the future an option to restrict Sealed classes implementation to Data classes? With that restriction previous method would be:
    fun MyModel.addEnvironmentToTitle(env: String) = copy(title = title + env)
    d
    s
    +3
    • 6
    • 11
  • t

    Tuan Kiet

    05/28/2019, 6:22 AM
    anyone here using inline class with mockito before? Mockito gets confused when I’m trying to mock a method with the return type is an inline class. It basically says something like
    can not mock this method with return type String but got Url instead
    s
    l
    • 3
    • 3
  • g

    galex

    05/28/2019, 9:34 AM
    Hey, do we have a map function but where I can “skip” returning elements depending on some condition? Kind of a reduce?
    g
    s
    +2
    • 5
    • 8
  • a

    amadeu01

    05/28/2019, 12:43 PM
    will anyone register to the kotlin hero contest ? i'm trying to enter using gmail into the codeforces.com, but I'm unable to login into the site, anyone with problems?
    p
    • 2
    • 2
  • a

    Adrián

    05/28/2019, 2:36 PM
    Does nobody know more about this general problem??
    m
    s
    +4
    • 7
    • 33
  • d

    dumptruckman

    05/28/2019, 6:23 PM
    It kinda seems like this exception that is happening is just being silently snuffed out
    r
    • 2
    • 6
  • b

    bbaldino

    05/28/2019, 6:59 PM
    is there any built-in annotation to suppress 'unused' warnings for methods in a library? i.e. 'API methods' used by other code. or a good way i could define one?
    r
    c
    +2
    • 5
    • 8
  • m

    mp

    05/28/2019, 8:11 PM
    I could really use unsigned types (parsing a binary format)… how sane is it to adopt unsigned types at their current maturity? Are they experimental like coroutines (works great, but api changes may come) or experimental like running a prerelease jvm (all hell may break loose, etc)?
    m
    • 2
    • 2
  • a

    Atendra Singh

    05/29/2019, 2:05 AM
    Admin please create a separate channel for Kotlin-Multiplatform
    😑 2
    a
    m
    k
    • 4
    • 4
Powered by Linen
Title
a

Atendra Singh

05/29/2019, 2:05 AM
Admin please create a separate channel for Kotlin-Multiplatform
😑 2
a

AngusMorton

05/29/2019, 2:06 AM
#multiplatform
m

Mike

05/29/2019, 2:14 AM
And #meta would likely be a good channel for requests like that. But first search channels. And it's not necessary to cross post in many channels for a request.
k

karelpeeters

05/29/2019, 8:06 AM
And you don't need an admin to create channels, everyone can do so.
m

Mike

05/29/2019, 11:21 AM
And one final FYI. Everything in here is kotlin focused, so there wouldn't be a need for a channel prefix. Occasionally conversations will go off topic, but this is a Kotlin 'only' Slack.
View count: 3