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

    janvladimirmostert

    11/20/2018, 8:58 PM
    is it possible to define reified generic types in an interface or will i have to pass in the type as a second parameter? simple example that i'm playing around with:
    interface JsonProvider {
    	fun <T> fromJson(input: String): T
    	fun <T> fromJsonList(input: String): List<T>
    }
    Gson for example now requires the class type to be passed in:
    class Blah : JsonProvider {
    
    	val gson = com.google.gson.Gson()
    
    	override fun <T> fromJson(input: String): T {
    		return gson.fromJson(input, T::class.java)
    	}
    unless that
    T
    is reified and fromJson / fromJsonList are inlined, IntelliJ complains and reifying that T inside the interface doesn't seem to be supported.
    d
    r
    • 3
    • 3
  • u

    Uzi Landsmann

    11/20/2018, 11:20 PM
    Listened to an awesome talk by @kevinmost today at Øredev, about idiomatic Interop with Kotlin. He also said he’s going to create a compiler plugin which will create builders for kotlin classes to allow usage from Java. Is it finished yet Kevin? :)
    😍 1
    g
    • 2
    • 10
  • e

    edwardwongtl

    11/21/2018, 4:25 AM
    A question related to reflection and `data class`’s copy method. Currently I am have something like this
    enum class GeneralModifier {
        Less, Normal
    }
    
    data class Latte(
        val ice: GeneralModifier = GeneralModifier.Normal,
        val milk: GeneralModifier = GeneralModifier.Normal
    ) : Coffee()
    And the selection input is
    Pair<String, Enum<GeneralModifier>>
    , where the first one is the field name, e.g. “ice” So I do
    tem.copy(
      ice = if (field == "ice") GeneralModifier.values().first { it == option } else item.ice,
      milk = if (field == "milk") GeneralModifier.values().first { it == option } else item.milk
    )
    Is there a easier way to do the
    copy
    ?
    j
    • 2
    • 6
  • b

    Bernhard

    11/21/2018, 10:16 AM
    I would have expected the inliner to just copy the code as is and file in all the type parameters with the real type variable
    d
    • 2
    • 17
  • z

    zokipirlo

    11/21/2018, 11:28 AM
    Hi! Still learning functional things in Kotlin and I'm not sure if solution is done optimal. Can someone please check my example and tell me if this can be done better? https://try.kotlinlang.org/#/UserProjects/h9ra2isjl4vudcq3mmo8gii4n8/fb6lvfgtq7ppf3es5tt36b5h0o Thanks!
    k
    • 2
    • 2
  • s

    sindrenm

    11/21/2018, 12:00 PM
    Is there a way to globally enable contracts in Kotlin 1.3? Per module or even throughout the entire project. It's a little tedious to add the
    @ExperimentalContracts
    annotation absolutely everywhere. Thanks! :D Not entirely sure where to ask for this. If it's suitable for another channel, I'd be happy to move the question over there.
    👍 1
    d
    • 2
    • 3
  • g

    gsala

    11/21/2018, 1:35 PM
    Can I declare an enum class that has the same name as one of its members in Kotlin. Example:
    enum class Potato(val a : Int) {
         Potato(3);
    }
    This is possible in Java but it seems like it's not allowed in Kotlin?
    p
    d
    s
    • 4
    • 12
  • a

    Adrian Wawrzak

    11/21/2018, 2:27 PM
    hi, is Any::class.java equivalent in Kotlin to Object.class from Java?
    :yes: 2
    h
    • 2
    • 1
  • s

    sindrenm

    11/21/2018, 2:56 PM
    Hmm, Kotlin (on the JVM in this case) defines some new exceptions and also aliases some of Java's exceptions (like
    kotlin.RuntimeException
    is actually just a typealias for
    java.lang.RuntimeException
    ). And all of Kotlin's own exceptions will ultimately inherit from
    kotlin.Throwable
    , whereas Java's exceptions will inherit from
    java.lang.Throwable
    ). But does that mean that catching
    kotlin.Throwable
    only won't actually catch e.g. `java.lang.RuntimeException`s?
    d
    • 2
    • 5
  • u

    user

    11/21/2018, 3:22 PM
    message has been deleted
    😶 1
    👍 9
    h
    • 1
    • 1
  • a

    Andrew Gazelka

    11/21/2018, 3:31 PM
    I am looking at docs and see this. Why wouldn't
    isEmpty
    be a function? Also wouldn't the value stored in
    isEmpty
    never be referenced?
    o
    s
    • 3
    • 13
  • a

    Andrew Gazelka

    11/21/2018, 3:42 PM
    also another (probably dumb) question. "Fields cannot be declared directly in Kotlin classes." umm... they can? I am confused
    d
    s
    • 3
    • 6
  • r

    reik.schatz

    11/21/2018, 4:03 PM
    is there a cheap way to deserialise a data class to a String and serialise it back from a String
    t
    p
    g
    • 4
    • 5
  • i

    igor.wojda

    11/21/2018, 4:33 PM
    Hey small question about this PR https://github.com/JetBrains/kotlin/pull/1994. I see it has been merged however I don’t see this commit on the list of commits on
    master
    branch here https://github.com/JetBrains/kotlin/commits/master. Am I looking at incorrect branch 🤔
    i
    • 2
    • 1
  • s

    Slackbot

    11/21/2018, 6:52 PM
    This message was deleted.
    s
    • 2
    • 3
  • a

    Andrew Gazelka

    11/21/2018, 7:28 PM
    I am taking code which makes the most sense in a linear fashion and inputting it into an executor which is iterative. This seems to call for a
    sequence{}
    ... except I wouldn't return anything and just execute... (so if I used 'yield' I would have to return meaningless values). Is there a better way to implement this?
    k
    • 2
    • 1
  • i

    ienoobong

    11/22/2018, 6:28 AM
    I updated IDEA to 2018.3 now I can't use Kotlin because I get Incompatible with the current IntelliJ IDEA version Please what can I do to resolve?
    j
    g
    a
    • 4
    • 7
  • k

    kschlesselmann

    11/22/2018, 7:08 AM
    Hi there! Currently I need a little advice on kotlin, mutable/readonly collections and MongoDB mappings. My current minimal setup is for example
    import org.springframework.boot.ApplicationRunner
    import org.springframework.boot.autoconfigure.SpringBootApplication
    import org.springframework.boot.runApplication
    import org.springframework.context.annotation.Bean
    import org.springframework.data.annotation.Transient
    import org.springframework.data.mongodb.core.mapping.Field
    import org.springframework.data.repository.reactive.ReactiveCrudRepository
    import org.springframework.stereotype.Repository
    import reactor.core.publisher.Flux
    import java.util.*
    
    class Test(
            list: List<String>,
            val id: UUID = UUID.randomUUID()
    ) {
    
        @Field("list")
        private val _mutableList: MutableList<String> = list.toMutableList()
    
        val list: List<String>
            @Transient get() = _mutableList
    }
    
    @Repository
    interface TestRepository : ReactiveCrudRepository<Test, UUID>
    
    @SpringBootApplication
    class DemoMongoMappingApplication {
    
        @Bean
        fun runner(testRepository: TestRepository) = ApplicationRunner {_ ->
            Flux.just("a", "b", "c")
                    .map { Test(listOf(it)) }
                    .collectList()
                    .flatMapMany { testRepository.saveAll(it) }
                    .flatMap { testRepository.findById(it.id) }
                    .subscribe { println("Found $it.id") }
        }
    }
    
    fun main(args: Array<String>) {
        runApplication<DemoMongoMappingApplication>(*args)
    }
    Sadly this fails during load of my entities with
    org.springframework.data.mapping.MappingException: No property list found on entity class com.example.demomongomapping.Test to bind constructor parameter to!
    . The problem seems to be with the backing property
    _list
    . Any suggestions how you solve those issues?
    k
    a
    • 3
    • 7
  • l

    liusbl

    11/22/2018, 12:04 PM
    Is this expected behaviour? If so, can someone explain why?
    a
    a
    • 3
    • 3
  • f

    frellan

    11/22/2018, 12:30 PM
    Why is there no package visibility modifier in kotlln? For example, I have a package for my DB access in my server. I want to only expose one class to the rest of the app to avoid confusion. In the package I also have several repositorieclasses for each of my enteties, I do not want for example the controllers package to access those repositories directly, I want it instead to go through my master
    DB
    class. How can I do that in kotlin?
    u
    a
    +2
    • 5
    • 11
  • k

    kschlesselmann

    11/22/2018, 1:11 PM
    Does anyone know if there's a solution to kotlin + JaCoCo? I cannot meet my quality gates in sonar because coverage is too low. There are a couple of functions that should be covered though
    c
    m
    m
    • 4
    • 9
  • s

    serebit

    11/22/2018, 3:10 PM
    Any chance of a date/time feature set appearing in the standard library? It’d be pretty useful for multiplatform
    👍 4
    j
    k
    • 3
    • 3
  • s

    serebit

    11/22/2018, 4:14 PM
    I'm writing a cross-platform (jvm + native) library, a Kotlin date/time library or feature set would help immensely.
    m
    • 2
    • 2
  • c

    coder82

    11/22/2018, 4:52 PM
    Does the for/in loop use iterator() underneath?
    :yes: 1
    🇳🇴 1
    👍 1
    i
    • 2
    • 1
  • c

    coder82

    11/22/2018, 4:55 PM
    so there is no point of doing: list.iterator().forEach instead of: list.forEach
    i
    • 2
    • 1
  • j

    jmfayard

    11/22/2018, 5:23 PM
    I am looking for a static analysis tool that given a className prints to the console its Type Hierarchy in my project. Example
    $ ./staticAnalysis android.app.Activity
    android.app.Activity
      \-- FragmentActivity
        \-- AppCompatActivity
             \-- MyActivity1
             \-- MyActivity2
    Does that exist?
    i
    • 2
    • 3
  • i

    igor.wojda

    11/22/2018, 5:27 PM
    Android project:
    Koin
    or
    Kodein
    and why?
    j
    e
    +3
    • 6
    • 10
  • s

    Shawn

    11/22/2018, 7:49 PM
    kind of an academic, please-don’t-think-I’m-actually-using-this sorta question - is there any sort of provision to have two methods with the same name and signature, but with one having a type parameter (specifically
    reified
    vs no type param, (thanks for clarifying @halley))? the compiler complains about a platform declaration clash, which I suppose makes sense since there’s no real overloading happening there, but since the second method has to be
    inline
    anyhow, could the compiler not figure out what you mean at compile time and inline the appropriate method to avoid the signature clash?
    h
    j
    d
    • 4
    • 12
  • d

    dewildte

    11/22/2018, 8:17 PM
    Anyone here use GitKraken on Windows?
    a
    d
    • 3
    • 3
  • s

    Slackbot

    11/22/2018, 11:15 PM
    This message was deleted.
    🚓 2
    ⚠️ 2
    s
    • 2
    • 2
Powered by Linen
Title
s

Slackbot

11/22/2018, 11:15 PM
This message was deleted.
🚓 2
⚠️ 2
s

Shawn

11/22/2018, 11:18 PM
I… what
oh, let me guess - the shortlink includes an affiliate link so even after people realize the scam, you guys still get some cash from the click-through (assuming they still buy something else on Amazon)
View count: 2