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
getting-started
  • s

    s.luhmirins

    02/23/2017, 10:11 AM
    afaik, it means that class is not nullable
    r
    • 2
    • 3
  • d

    darkmoon_uk

    02/23/2017, 10:15 AM
    I’m trying to use coroutines and have defined a ‘suspend’ function correctly. However, the call-site fails to compile with ‘should be called only from a coroutine or another suspend function’. I realise that some mechanism to bridge Kotlins coroutine system with Androids MainLooper must be required; but how to implement it?
    e
    g
    • 3
    • 10
  • a

    Andreas Sinz

    02/23/2017, 10:42 AM
    class CounterMap(val map: MutableMap<String, Int>): MutableMap<String, Int> by map {
        override fun put(key: String, value: Int): Int? {
            val previousValue = map[key]
            
            map[key] = (previousValue ?: 0 ) + value
            	
            return previousValue
        }
    }
    n
    • 2
    • 3
  • e

    elezium

    02/26/2017, 2:57 AM
    Hi folks, is there any know issue / limitation of using Java EE with Kotlin?
    r
    • 2
    • 2
  • l

    liminal

    02/26/2017, 7:08 PM
    Hi all, what is a good way to format a timestamp that's currently stored as millis Long as a date?
    b
    w
    • 3
    • 3
  • m

    miha-x64

    02/27/2017, 2:06 PM
    Is there a way to declare
    Map<String, exactly Any>
    , not
    out Any
    , to use with Retrofit? Currently using
    MutableMap
    as a workaround.
    i
    • 2
    • 2
  • q

    quver

    02/27/2017, 4:31 PM
    Hello guys, how can I run kotlin extensions from java?
    m
    r
    • 3
    • 7
  • c

    cedric

    02/27/2017, 6:44 PM
    (sorry the ping was meant for @robin, not @kiesel)
    r
    • 2
    • 1
  • o

    okkero

    02/28/2017, 11:53 AM
    @aslan I guess the answer would have been more obvious if the Java declaration had been more correctly written as
    Map<String, Class<?>> hm = new HashMap<>();
    (notice the wildcard)
    a
    • 2
    • 2
  • n

    north

    02/28/2017, 12:16 PM
    @Andreas Sinz
    private val myMap = mutableMapOf<String, Long>()
        private fun defaultValue(): Long = 5
        fun get(key: String) {
            myMap.getOrPut(key, ::defaultValue)
        }
    a
    • 2
    • 13
  • j

    jan.rabe

    03/02/2017, 3:59 PM
    there are cases where i want a default behaviour on instantiation if the parameters are not valid
    a
    a
    • 3
    • 4
  • r

    robin

    03/03/2017, 2:50 PM
    @xxxifan Do you have a
    fun main(args: Array<String>)
    anywhere in your project?
    x
    • 2
    • 4
  • x

    xxxifan

    03/03/2017, 2:54 PM
    the kotlin icon come out!
    r
    • 2
    • 5
  • g

    gbm

    03/04/2017, 2:14 PM
    For instance collection requires BiFunction, could I pass Kotlins lambda?
    e
    • 2
    • 8
  • x

    xxxifan

    03/05/2017, 2:09 PM
    why kotlin has to assign a field var a default value?it says "Property must be initialized or be abstract“
    b
    j
    v
    • 4
    • 4
  • b

    benleggiero

    03/05/2017, 3:55 PM
    Why can't a
    data class
    be extended?
    m
    • 2
    • 1
  • c

    camdenorrb

    03/06/2017, 5:33 AM
    Is there a better way to write that?
    o
    • 2
    • 1
  • a

    angarron

    03/06/2017, 9:44 PM
    Hi all! I am glad I was able to easily find an active Kotlin community. I have a simple question re: data classes + constructors, let me know if this is the right or wrong place to ask. I'm not exactly a beginner but maybe this will help others 😛 In short, I want to have a complex constructor for a
    data class
    . It's easiest to understand by example. I have something like this contrived example:
    data class ManageUserHelper(val canKick: Boolean, val canBan: Boolean)
    but I want to have an initialization flow where those booleans are computed:
    constructor(val actingUser: User, val targetUser: User, val relationship: Relationship) {
      val canKick = // do something complicated w/ users + relationship
      val canBan = // do something complicated w/ users + relationship, which may depend on the above
      this(canKick, canBan)
    }
    ^ Obviously the above does not compile because the secondary constructor does not immediately delegate to the primary constructor. Until now I have solved this problem by moving that secondary constructor into a
    buildFrom
    method inside of a
    companion object
    but that feels messy to me. Is there a more idiomatic way to accomplish what I want? Thanks for the help, and again let me know if there is a better place to ask!
    v
    • 2
    • 1
  • a

    angarron

    03/06/2017, 10:19 PM
    So if you'd like to expand on why it is better to create a non-data class and override those methods myself, please do as I would love to understand it. If not, that's okay too, I trust you on that one even though that won't stop me from wishing there was an annotation I could use to request those overrides anyway 😛
    r
    • 2
    • 7
  • e

    ehubbard

    03/06/2017, 11:45 PM
    how well trod is the “compile kotlin within ant” user story?
    v
    • 2
    • 3
  • m

    minikloon

    03/07/2017, 7:32 AM
    Serialize a float in little endian.
    a
    • 2
    • 5
  • b

    benleggiero

    03/10/2017, 1:41 AM
    So, tell me if I'm wrong. AFAIK,
    inline
    sacrifices the size of the binary in favor of fewer stack frames and faster execution.
    Is that correct? Is it more subtle or complex? Is there anything else it does that I should know?
    v
    • 2
    • 8
  • n

    nkiesel

    03/10/2017, 2:14 AM
    when would I use the K-1.1
    also
    instead of
    apply
    ?
    r
    • 2
    • 1
  • d

    deusex

    03/11/2017, 8:59 PM
    Ok, thank you. This means Kotlin does not offer something fancy for this case.
    b
    • 2
    • 1
  • e

    elezium

    03/14/2017, 1:27 AM
    Hi folks, which Test framework are you using with Kotlin? JUnit or there's better alternatives?
    o
    e
    • 3
    • 3
  • k

    kingsley

    03/14/2017, 1:43 PM
    This should work:
    source.retryWhen { errors ->  
      errors
        .zipWith(Observable.range(1, 3)) { n, i -> i }
        .flatMap { retryCount -> Observable.timer(Math.pow(5.0, retryCount.toDouble()).toLong(), TimeUnit.SECONDS) }
    }
    I suppose you're on RxJava1?
    👍 1
    r
    r
    • 3
    • 6
  • a

    appasni

    03/17/2017, 6:06 PM
    Ole, Kevin, Yes, but on the 2nd line I'm explicitly specifying the type to be
    String
    and not
    String?
    or letting it be inferred which would probably be
    String?
    i
    • 2
    • 1
  • v

    voddan

    03/17/2017, 6:26 PM
    You can do
    val s = buildSequence { while(true) yieldAll(list) }
    i
    f
    • 3
    • 3
  • m

    menegatti

    03/18/2017, 12:17 PM
    (Boolean) -> String
    is the function type
    a
    • 2
    • 1
  • m

    minikloon

    03/19/2017, 9:42 AM
    One issue I had with a custom context was that the kotlin built-in delay function fails silently if if the continuation interceptor doesn't implement Delay.
    v
    • 2
    • 5
Powered by Linen
Title
m

minikloon

03/19/2017, 9:42 AM
One issue I had with a custom context was that the kotlin built-in delay function fails silently if if the continuation interceptor doesn't implement Delay.
v

voddan

03/19/2017, 9:51 AM
Could you elaborate on that? Maybe in #coroutines
m

minikloon

03/20/2017, 2:03 AM
I mean the delay method in Delay.kt

http://i.imgur.com/chGCZUS.png▾

If the ContinuationInterceptor property of the context doesn't implement Delay, it just doesn't continue and doesn't say a word.
v

voddan

03/20/2017, 3:33 AM
Hm, does it fail silently? Because the code looks like it does something
m

minikloon

03/20/2017, 1:49 PM
Well it cancels the task and the continuation doesn't happen.
View count: 4