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

    damian

    03/15/2017, 5:43 PM
    I'm slightly mistaken. It only happens when the public final field is from another module. Still an unexpected breaking change.
    s
    • 2
    • 1
  • n

    nkiesel

    03/15/2017, 6:52 PM
    wen I tried to explain the difference between
    class
    ,
    sealed class
    and
    open class
    to a co-worker he asked: why is
    sealed
    not the default, given that developer has control on what goes into the same file anyway (i.e. why is
    class
    not the same as
    sealed class
    )? I did not have a good answer. can anyone help me out?
    v
    l
    c
    • 4
    • 5
  • j

    jackmiras

    03/16/2017, 2:04 AM
    Hey everyone, what are you guys using for dependency injection?
    d
    u
    m
    • 4
    • 12
  • c

    cedric

    03/16/2017, 6:30 AM
    @voddan I get pretty good results looking for "kotlin" on youtube
    v
    • 2
    • 2
  • t

    thijs

    03/16/2017, 9:41 AM
    Doe anyone have the Kotlin logo as a vector image?
    👍 3
    h
    a
    • 3
    • 3
  • r

    robin

    03/16/2017, 12:54 PM
    d.toString().trim('0')
    would be one way
    m
    p
    l
    • 4
    • 10
  • d

    danko9

    03/16/2017, 1:38 PM
    @vach Would you mind elaborating on your asSequeence() comment? Or sending a link?
    v
    • 2
    • 4
  • i

    ilya.gorbunov

    03/16/2017, 1:44 PM
    📣 📣 📣 We have published v0.1 of Kotlin immutable collections library https://discuss.kotlinlang.org/t/kotlinx-collections-immutable-v0-1-has-been-published/2403/2
    🎉 7
    n
    • 2
    • 5
  • u

    user

    03/16/2017, 3:35 PM
    message has been deleted
    g
    • 1
    • 1
  • e

    eygraber

    03/16/2017, 4:50 PM
    I find that a lot of times I have a nullable object, and it sits in the middle of a call chain, and I don't want the whole chain to become nullable after it, and I don't want to use ?: because I have a sensible default that I could plug in. Could anything go wrong with using something like the following?
    fun <T: Any?> T?.or(other: T): T {
      return if(this == null) {
        other
      }
      else {
        this
      }
    }
    g
    m
    s
    • 4
    • 9
  • b

    bitkid

    03/16/2017, 5:08 PM
    https://kukuruku.co/post/why-kotlin-sucks/ half serious but funny read
    f
    • 2
    • 2
  • k

    koral

    03/17/2017, 1:25 AM
    I have a function like this:
    override fun processNewLines(lines: Array<String>) = lines.forEach { <http://logger.info|logger.info>(it) }
    and it works as expected however when I change last invocation to lambda:
    override fun processNewLines(lines: Array<String>) = lines.forEach { logger::info }
    code compiles fine but there is a runtime error
    java.lang.NoSuchMethodError: kotlin.jvm.internal.FunctionReference.<init>(ILjava/lang/Object;)V
    at that line
    k
    • 2
    • 2
  • n

    nulldev

    03/17/2017, 3:04 AM
    Does anybody know why calling
    toByte()
    on
    -128
    results in
    128
    ? Java bytes can only hold
    -128
    to
    127
    anyways! Example code:
    fun main(args: Array<String>) {
        println(-128.toByte())
        println(-127.toByte())
    }
    Result:
    128
    -127
    Casting
    -128
    to
    byte
    in Java returns
    -128
    as expected.
    u
    • 2
    • 1
  • m

    mg6maciej

    03/17/2017, 8:37 AM
    inline fun <reified T : Any> myFunc() = myFuncImpl(T::class)
    
    internal fun <T : Any> myFuncImpl(clazz: KClass<T>) {}
    #language-proposals How about making this compile?
    o
    m
    +2
    • 5
    • 44
  • p

    pavlospt

    03/17/2017, 2:31 PM
    And what I want is to just call that method on something like:
    override fun <T> getFoo() : T? { return fromBytes(byteArray) }
    o
    • 2
    • 11
  • u

    udalov

    03/17/2017, 7:55 PM
    a YT issue would be appreciated
    m
    • 2
    • 1
  • o

    orangy

    03/18/2017, 1:37 AM
    A common pitfall with lazy evaluation is capturing the context and storing resulting lazy computation in a field along with all the captured locals and whatever they hold. Hence, hard to debug memory leaks.
    🤔 1
    g
    • 2
    • 1
  • d

    david.bilik

    03/18/2017, 7:00 PM
    out of nowhere this error happens when I try to build project
    Error:(5, 0) For input string: ""
    Open File
    Nothing changes and the line in build.gradle is
    apply plugin: ‘kotlin-android’
    . The stacktrace of error says
    Failed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes precedence.
    java.lang.IllegalStateException: buildToolsVersion is not specified.
    Of course my build tools version is set If i build my project with —stacktrace option, this is what is printed in console
    Caused by: java.lang.NumberFormatException: For input string: ""
      at org.jetbrains.kotlin.incremental.CacheVersion.getActualVersion(
      at org.jetbrains.kotlin.incremental.CacheVersion.checkVersion(
      at org.jetbrains.kotlin.incremental.BuildCacheStorage.<init>(
      at org.jetbrains.kotlin.gradle.plugin.KotlinGradleBuildServices.<init>(
    
      at org.jetbrains.kotlin.gradle.plugin.KotlinGradleBuildServices.<init>(
    
      at org.jetbrains.kotlin.gradle.plugin.KotlinGradleBuildServices$Companion
    
      at org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper.apply(
    
      at org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper.apply(
    
      at org.gradle.api.internal.plugins.ImperativeOnlyPluginApplicator.
    
      at org.gradle.api.internal.plugins.RuleBasedPluginApplicator.
    
      at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(
    
      ... 72 more
    • 1
    • 1
  • j

    johnl

    03/18/2017, 10:12 PM
    Error:(46, 0) Could not find method kotlin() for arguments [build_4fp1tow4qcx2530bdrl2gp05n$_run_closure2$_closure19$_closure20@78ae7c54] on source set 'main' of type org.gradle.api.internal.tasks.DefaultSourceSet.
    m
    • 2
    • 8
  • t

    tschuchort

    03/20/2017, 1:06 PM
    why can't you use
    _
    as a parameter name in normal functions?
    c
    g
    +2
    • 5
    • 13
  • z

    zak.taccardi

    03/20/2017, 7:27 PM
    can I tell a constructor's var to have a private set?
    v
    • 2
    • 1
  • g

    groostav

    03/20/2017, 9:21 PM
    i hate build systems so much.
    e
    c
    • 3
    • 7
  • m

    mp

    03/20/2017, 9:30 PM
    When I have a lambda used as an single-method interface, and that interface method takes 2 parameters, the lambda needs to 2 params also. If I don't use one of the params in a particular instance, the compiler warns me that the param is unused, but of course I cannot delete the param. Is there a workaround, or some way to indicate to the compiler what's going on?
    k
    • 2
    • 1
  • l

    linear

    03/20/2017, 10:29 PM
    I'm trying to create a HashMap that aggregates a bunch of objects, and these objects use the init blocks to register themselves by adding themselves into the HashMap. Unfortunately, it appears to me that Kotlin is thinking that since I never access the objects directly (by name) that they should never initialize, which leaves my HashMap empty
    g
    • 2
    • 4
  • r

    rwachol

    03/21/2017, 10:14 AM
    ndk, slow gradle compilation
    m
    j
    • 3
    • 3
  • v

    vach

    03/21/2017, 11:09 AM
    dont want to continue the eclipse theme but small story for you few years ago i was at vmware, everyone used myeclipse, same eclipse but you pay for it, they told me that there is technical support for this one thats why its paid... (really if you need technical support to use your ide probably its a bad ide)... i had hard time configuring everything for intellij but i managed it, worked there 2 years, people would "wow" when they see me using multicursors or some fancy intellij features that eclipse users never dreamed of... lately visited my team, everyone were using intellij moral of the story : imho sometimes its better to leave old tools to die and focus on tools that actually get the work done
    m
    j
    • 3
    • 11
  • g

    ghosalmartin

    03/21/2017, 4:09 PM
    If I have a data class thats mostly nullables, is there anyway to quickly cast all of them to non null? or is it just a matter of having to do the null checks manually?
    m
    • 2
    • 3
  • l

    linear

    03/21/2017, 9:00 PM
    so… just discovered that ‘protected' also grants visibility to all classes in the same package. Been doing Java a long time and somehow never noticed O_O
    v
    • 2
    • 2
  • e

    ean5533

    03/22/2017, 3:17 PM
    I'm pretty sure this is the 3rd or 4th time I've forgotten the correct name for that method
    m
    • 2
    • 1
  • s

    svenjacobs

    03/23/2017, 7:32 AM
    @moelholm I believe the difference is whether a Java
    Class
    or a Kotlin
    KClass
    is expected.
    ::class.java
    will return
    Class
    .
    m
    o
    • 3
    • 3
Powered by Linen
Title
s

svenjacobs

03/23/2017, 7:32 AM
@moelholm I believe the difference is whether a Java
Class
or a Kotlin
KClass
is expected.
::class.java
will return
Class
.
m

moelholm

03/23/2017, 7:55 AM
Hi Sven. I think you are spot on. But the @RunWith JUnit annotation does indeed expect a Class. When I look in IntelliJ. But I guess that a KClass "is-a" Class when observed from Java... and perhaps that's enough for the JUnit runner framework to work
o

okkero

03/23/2017, 8:08 AM
This is a special case for annotations. A
KClass
does not in general share an is-a relationship with
Class
See quote: "If you need to specify a class as an argument of an annotation, use a Kotlin class (KClass). The Kotlin compiler will automatically convert it to a Java class, so that the Java code will be able to see the annotations and arguments normally." https://kotlinlang.org/docs/reference/annotations.html#constructors
m

moelholm

03/23/2017, 8:14 AM
Awesome, Ole - thanks for the explanation
View count: 6