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

    Marc Knaup

    11/29/2018, 9:51 PM
    Did anybody manage to get codecov.io working with Kotlin + JaCoCo when source path and package name do not match? The generated coverage report XML only contains source file names, not paths, which prevents codecov from reporting any coverage 😞
    p
    g
    • 3
    • 4
  • h

    Hullaballoonatic

    11/29/2018, 9:59 PM
    is there a unifying comparable class to which all primitive numbers belong, or better yet, one on which you can use mathematical operators?
    s
    k
    • 3
    • 26
  • h

    Hullaballoonatic

    11/29/2018, 11:11 PM
    + concatenates strings, but not numbers
    b
    • 2
    • 2
  • s

    Shawn

    11/29/2018, 11:14 PM
    in any event, implement it yourself
    infix fun <http://Int.cat|Int.cat>(other: Int): Int = (toString() + other.toString()).toInt()
    🐱 1
    h
    b
    • 3
    • 7
  • d

    diesieben07

    11/29/2018, 11:14 PM
    a * pow(10, log10(b)) + b
    h
    b
    • 3
    • 4
  • s

    Shawn

    11/29/2018, 11:15 PM
    Are you sure you wouldn’t rather just write R? Maybe Matlab? lol
    🤣 1
    😛 1
    h
    • 2
    • 1
  • h

    Hullaballoonatic

    11/29/2018, 11:36 PM
    to me, is a worthwhile trade-off, but why not both?
    k
    • 2
    • 2
  • a

    agrosner

    11/30/2018, 2:30 AM
    Per earlier question about data class extending sealed class and duplicating properties in the constructor, is there plans to add inheriting constructors? Something like what swift supports where if a subclass doesn't define a constructor, it inherits the constructor of the super class.
    b
    • 2
    • 4
  • k

    kschlesselmann

    11/30/2018, 7:42 AM
    My
    enum class
    looks like
    enum class Condition {
    
        EXACT {
            override fun evaluate(actual: Set<String>, expected: Set<String>) = actual == expected
        },
    
    //....
    
        abstract fun evaluate(actual: Set<String>, expected: Set<String>): Boolean
    }
    t
    h
    • 3
    • 8
  • c

    coder82

    11/30/2018, 8:47 AM
    then I guess rather pass "this" ?
    m
    k
    d
    • 4
    • 13
  • t

    thijs

    11/30/2018, 10:50 AM
    So right now I have something like this:
    private val journeyId by DetailFragmentArgs.journeyId
    And I would like to make this lazy
    a
    k
    • 3
    • 10
  • b

    bartvh

    11/30/2018, 1:01 PM
    Generics are great, but when building code that uses runtime type information the compiler sometimes needs to be told to shut up 😄 In this case involving enums, however, I can't get it to do so without using reflection:
    when (v) {
                is Enum<*> -> {
                    val ev: Enum<*> = v
                    val kc: KClass<Enum<*>> = ev.javaClass.kotlin
                    val ser: EnumSerializer<*> =
    //                        EnumSerializer(kc)
                            EnumSerializer::class.primaryConstructor!!.call(kc)
    Does anybody know a combination of casts/suppressions/*/magical incantations that could allow the commented out line to work?
    h
    • 2
    • 6
  • y

    Yogesh Gosavi

    11/30/2018, 4:27 PM
    What's difference between reduce and fold ?
    h
    s
    n
    • 4
    • 10
  • a

    Alowaniak

    11/30/2018, 9:32 PM
    So I was messing around with something and tried to do a delegate (Comparable) by a primitive, but then there's some internal error in the compiler instead of syntax error or w/e?
    i
    • 2
    • 3
  • a

    Andrew Gazelka

    12/01/2018, 4:28 AM
    how should I make a delegate with a default value from a config if the current val DNE or is the wrong type? From what I see, I would need to have both
    DelegateClass<A>
    and
    inline operator fun <reified T> getValue
    which would look really messy since we are assuming
    A
    and
    T
    are the same. I would need to do this, because I need to input the default value into the class, but classes can't be reified.
    k
    h
    • 3
    • 6
  • y

    Yutsa

    12/01/2018, 6:12 PM
    Hello, I have an issue with Spring Boot and Junit4 testing
    @SpringBootTest
    class ParsingIntegrationTest(@Autowired val cardPriceService: CardPriceService) {
    It gives me this error :
    java.lang.Exception: Test class should have exactly one public zero-argument constructor
    m
    • 2
    • 1
  • h

    hudsonb

    12/01/2018, 6:30 PM
    But there isn't a kotlin stdlib solution that I'm aware
    e
    i
    • 3
    • 5
  • m

    Marcin Wisniowski

    12/01/2018, 11:43 PM
    I'm trying to write a Kotlin contract so I can get smart casts in code calling my function, but this syntax doesn't work, what's the correct way to achieve this?
    s
    k
    • 3
    • 19
  • k

    karelpeeters

    12/02/2018, 11:23 AM
    Found the link to the last time I found this 😒imple_smile:
    👌 1
    ➿ 1
    t
    j
    • 3
    • 8
  • r

    rrader

    12/02/2018, 1:14 PM
    object Users  {
        val id: Long = 10
        val name : String ="name"
        val cityId : Long = 42
    }
    
    
    fun main(args: Array<String>) {
        slice(Users::name)
    }
    
    fun slice(vararg properties: KProperty<Users>) {
        properties.forEach { println(it.name) }
    }
    what should be
    properties
    type that will accept only Users properties?
    t
    • 2
    • 3
  • b

    bod

    12/02/2018, 4:40 PM
    Hello, Word! I was wondering if there's any way to craft a Java method in such a way that it can be called in Kotlin like a "function literals with receiver". So I could call
    myObj.foo { bar() }
    where
    bar
    is a method on some class passed as the receiver of the lambda - but
    foo
    is declared/implemented in Java. Ideas? 🙂
    a
    t
    • 3
    • 12
  • k

    keturn

    12/02/2018, 8:00 PM
    why doesn't my environment seem to be able to find this function? https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.streams/kotlin.sequences.-sequence/as-stream.html does my JRE_1.8.0 not have Streams or something?
    a
    • 2
    • 2
  • s

    silas.schwarz

    12/03/2018, 10:25 AM
    Hey 👋, i'm totally aware of the fact that this is some what unconventional but why not give it a try. my current employer sadly decided to turn kotlin the cold shoulder. I've used it for the past ~1.5 years, mostly creating SpringBoot Backend Apps aka microservices and APIs, AWS Lambdas, http4k app, reactor rabbit apps. I really enjoy kotlin and would ❤️ to continue working with it. so... if you have a opening in your company, preferably in 🇩🇪 (not a must) and in the Frankfurt area (not a must) , please DM me here or on twitter @silasschwarz thx 🙇
    t
    r
    • 3
    • 3
  • m

    miguelsesma

    12/03/2018, 12:47 PM
    I know, but why it behaves differently in 1.2.71 and 1.3.0?
    p
    a
    • 3
    • 5
  • p

    Paul Woitaschek

    12/03/2018, 2:05 PM
    Is there any kind of discussion on union types?
    g
    • 2
    • 1
  • p

    Paul Woitaschek

    12/03/2018, 2:08 PM
    I have a class that takes a list of
    Any
    but the subtypes are not directly related so they can't be sealed classes.
    a
    • 2
    • 9
  • j

    Joe

    12/03/2018, 3:26 PM
    This works, but isn't really what I want:
    class PhaseDefinition<C: GameContextBase, T: GamePhaseBase<C>>(val init: PhaseDefinition<C, T>.() -> Unit) {...}
    r
    • 2
    • 9
  • a

    APXEOLOG

    12/03/2018, 4:26 PM
    Guys, i want to execute some code only once, i wonder if there is any way to implement function like
    ...
    once { some code ... }
    ...
    r
    b
    h
    • 4
    • 3
  • a

    APXEOLOG

    12/03/2018, 4:54 PM
    Yes, but i wondered is there is a way to create generic function for this instead of adding flags for every place like this
    d
    • 2
    • 7
  • a

    APXEOLOG

    12/03/2018, 5:09 PM
    Yeah, i actually did same thing with stacktraces
    private val checkPoints: MutableSet<String> = HashSet()
    
    fun once(action: () -> Unit) {
        val stackTrace = Throwable().stackTrace[1]
        val key = "${stackTrace.fileName}_${stackTrace.methodName}_${stackTrace.lineNumber}"
        if (!checkPoints.contains(key)) {
            checkPoints.add(key)
            action()
        }
    }
    
    fun main() {
        repeat(100) {
            once { print("Say hi!") }
        }
    }
    😱 3
    k
    a
    r
    • 4
    • 3
Powered by Linen
Title
a

APXEOLOG

12/03/2018, 5:09 PM
Yeah, i actually did same thing with stacktraces
private val checkPoints: MutableSet<String> = HashSet()

fun once(action: () -> Unit) {
    val stackTrace = Throwable().stackTrace[1]
    val key = "${stackTrace.fileName}_${stackTrace.methodName}_${stackTrace.lineNumber}"
    if (!checkPoints.contains(key)) {
        checkPoints.add(key)
        action()
    }
}

fun main() {
    repeat(100) {
        once { print("Say hi!") }
    }
}
😱 3
k

karelpeeters

12/03/2018, 7:12 PM
Tiny suggestion:
!checkPoints.contains(key)
is
key !in  checkPoints
a

Alan Evans

12/03/2018, 9:40 PM
Never check before adding a value, that's doing double work,
add
returns a boolean https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-set/add.html.
if (checkPoints.add(key)) {
    action()
}
r

rnpy

12/03/2018, 10:19 PM
not that I'd recommend using it anywhere except for debug stuff, but
Thread.currentThread().stackTrace
can give you current stacktrace without creation a Throwable
View count: 4