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

    eygraber

    07/04/2018, 4:04 AM
    Can anyone explain why the compiler can't smart cast
    b
    in
    b.isEmpty()
    but it does for
    a
    in
    a.isEmpty()
    ?
    val a: String? = null
    val b: String? = null
    when {
      a == null && b == null -> true
      a == null -> b.isEmpty()
      b == null -> a.isEmpty()
    }
    k
    3 replies · 2 participants
  • l

    lenois

    07/04/2018, 4:13 AM
    So I'm working on a project with dagger and kotlin, and including the kapt execution is giving me a whole bunch of xlint errors, it seems to process the annotations correctly, it's just crowding the compile logs quite a bit. here is the compiler config
    <plugin>
                    <groupId>org.jetbrains.kotlin</groupId>
                    <artifactId>kotlin-maven-plugin</artifactId>
                    <version>${kotlin.version}</version>
                    <executions>
                        <execution>
                            <id>kapt</id>
                            <goals>
                                <goal>kapt</goal>
                            </goals>
                            <configuration>
                                <sourceDirs>
                                    <sourceDir>${project.basedir}/src/main</sourceDir>
                                </sourceDirs>
                                <annotationProcessorPaths>
                                    <annotationProcessorPath>
                                        <groupId>com.google.dagger</groupId>
                                        <artifactId>dagger-compiler</artifactId>
                                        <version>${dagger.version}</version>
                                    </annotationProcessorPath>
                                </annotationProcessorPaths>
                            </configuration>
                        </execution>
                        <execution>
                            <id>compile</id>
                            <phase>process-sources</phase>
                            <goals>
                                <goal>compile</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>test-compile</id>
                            <phase>test-compile</phase>
                            <goals>
                                <goal>test-compile</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <jvmTarget>1.8</jvmTarget>
                        <compilerPlugins>
                            <!-- Or "jpa" for JPA support -->
                            <plugin>no-arg</plugin>
                        </compilerPlugins>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.jetbrains.kotlin</groupId>
                            <artifactId>kotlin-maven-noarg</artifactId>
                            <version>${kotlin.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>
    these are the errors, there are hundred of them
    [Xlint:cantFindType]
    [URLClassLoader@4914000c] error can't determine annotations of missing type org.springframework.cache.annotation.Cacheable
    when weaving type dagger.internal.codegen.BindingGraphValidator
    when weaving classes
    when weaving
     [Xlint:cantFindType]
    [URLClassLoader@4914000c] error can't determine annotations of missing type org.springframework.cache.annotation.CacheEvict
    when weaving type dagger.spi.DiagnosticReporter
    when weaving classes
    when weaving
    I tried scouring the internet without any luck, so I thought i'd check and see if anyone here had insights.
    s
    3 replies · 2 participants
  • e

    eygraber

    07/04/2018, 5:46 AM
    Does
    <data class>.copy
    do anything special in terms of GC, or is it the same as allocating a new object? If I have a list of objects that are instances of data classes in a performance critical part of my code, and I need to routinely update the value of one of their fields, would I be better off making it a
    var
    and updating it in place, or using
    copy
    ?
    s
    e
    2 replies · 3 participants
  • c

    coder82

    07/04/2018, 7:15 AM
    is there more info about the incremental compilation introduced in 1.2.50 ?
    ❓ 1
    g
    1 reply · 2 participants
  • d

    dimsuz

    07/04/2018, 10:21 AM
    Kotlin plugin update arrived in Android Studio. Any info on what changed?
    l
    1 reply · 2 participants
  • e

    Elena Shaverdova

    07/04/2018, 1:31 PM
    Is there any documentation about creating custom compilation target for Kotlin?
    k
    g
    +1
    5 replies · 4 participants
  • z

    zmarkan

    07/05/2018, 1:08 PM
    Hey everyone 👋 A few months ago I ran a survey about the state of Kotlin, and we just released the results in a report! You can find it here: https://pusher.com/state-of-kotlin Hope you find it interesting, and if you do - I’d really appreciate some social shares 🙂 There’s also a link to Kaggle where you can get the raw data from the responses. Also if you have any ideas of what I can do to make it better next year I’m all ears and open to feedback. Cheers!
    :kotlin-flag: 2
    👏 5
    :kotlin: 9
    👍 7
    c
    1 reply · 2 participants
  • t

    tschuchort

    07/05/2018, 5:57 PM
    is it possible to enforce at compile time surjectivity of a function to a sealed type (ignoring that some of the "case classes" may have properties or may be subclassed)?
    k
    1 reply · 2 participants
  • y

    yaakov

    07/06/2018, 1:15 AM
    What would be a good book to teach someone Kotlin with? Like a complete beginner
    s
    k
    13 replies · 3 participants
  • o

    Olekss

    07/06/2018, 6:55 AM
    when will SAM conversion will be implemented in Kotlin? I mean for Kotlin SAM interfaces
    👍 2
    m
    d
    +7
    25 replies · 10 participants
  • m

    marstran

    07/06/2018, 10:54 AM
    You can do
    unfilteredResultsCache.filterNot { it.value.timeStamp.toEpochSecond(offset) < lastHourEpoch }
    , which will only create 1 new collection. Not one collection for every element removed.
    c
    2 replies · 2 participants
  • s

    Sherub Thakur

    07/06/2018, 12:19 PM
    let' say I have a sealed class with two options SC -> {A, B}, and I want to create an interface which takes A or B as argument. Is there any way to do so. I would like to implement this interface in a class that takes only A as argument and similarly for B.
    s
    a
    3 replies · 3 participants
  • s

    spand

    07/06/2018, 12:34 PM
    Whats wrong with
    mutablemap.entries.removeIf {}
    ?
    👍 1
    k
    3 replies · 2 participants
  • g

    GarouDan

    07/06/2018, 1:52 PM
    hi guys, is there a channel to ask questions about datagrip or intellij, for example?
    n
    s
    4 replies · 3 participants
  • c

    christophsturm

    07/06/2018, 2:52 PM
    why does the mapValues[To] method pass the map entry and not only the key to the transform function?
    l
    n
    3 replies · 3 participants
  • f

    fred.deschenes

    07/06/2018, 6:59 PM
    am I going insane or do Kotlin's bitwise operations behave differently than Java's?
    System.out.println((byte) -84 & 0xFF); // 172
    println((-84).toByte() and (0xFF).toByte()) // -84
    r
    1 reply · 2 participants
  • z

    zake

    07/06/2018, 8:35 PM
    org.antlr.v4.runtime.ANTLRFileStream
    instead of
    org.antlr.runtime.ANTLRFileStream
    s
    4 replies · 2 participants
  • x

    x80486

    07/07/2018, 12:34 AM
    Certainly, I can make it work by not using a
    companion object
    and having the class annotated with
    @TestInstance(TestInstance.Lifecycle.PER_CLASS)
    ...but still, I would like to use the
    companion object
    approach. Is there any workaround for this?
    c
    1 reply · 2 participants
  • m

    mingkangpan

    07/07/2018, 4:28 PM
    not really, actually I wanted to use the ::variable.isInitialized from kotlin, which I cant
    k
    6 replies · 2 participants
  • k

    karelpeeters

    07/07/2018, 9:59 PM
    Implicit
    0
    returned, I didn't know this was
    C
    !
    fun foo(): Int {
        a@when (1) {
            1 -> return@a
        }
        return 8
    }
    
    println(foo()) //prints 0
    o
    4 replies · 2 participants
  • k

    karelpeeters

    07/08/2018, 1:43 PM
    Is there a way to get compiler warnings/errors when the return values of certain functions are ignored?
    o
    4 replies · 2 participants
  • r

    redrield

    07/08/2018, 3:41 PM
    If I have a
    List<List<T>>
    , is there a way to flatten it while adding items at the boundaries between the lists?
    k
    k
    12 replies · 3 participants
  • e

    eugene.kudelevsky

    07/09/2018, 1:22 PM
    Ok, we’ve tried to create a new Kotlin project from scratch and just call intArrayOf() in main() function on that machine, and we’ve got the same error 😞
    a
    i
    9 replies · 3 participants
  • w

    warriorprincess

    07/09/2018, 7:30 PM
    trying to remove duplicate items from list:
    result.filterIndexed{ i, n -> nums.indexOf(n) == i }
    l
    3 replies · 2 participants
  • s

    Shawn

    07/10/2018, 3:40 AM
    (0 until N).reversed()
    Did you mean
    n downTo 0
    c
    b
    2 replies · 3 participants
  • s

    Sergio Crespo Toubes

    07/10/2018, 10:55 AM
    Can i do something like this in kotlin?
    products.sort {
                a,b -> }
    a
    g
    14 replies · 3 participants
  • k

    karelpeeters

    07/10/2018, 11:03 AM
    If you know if advance you need distinct elements, use a set instead of
    list.distinct()
    .
    w
    a
    18 replies · 3 participants
  • m

    musachev

    07/10/2018, 2:24 PM
    Hello guys, is there separate channel or hashtag for kotlin-native?
    a
    l
    3 replies · 3 participants
  • a

    aballano

    07/10/2018, 3:13 PM
    Is it expected that this comparison returns false?
    (1L as Any)::class.java == (1L)::class.java
    r
    3 replies · 2 participants
  • a

    aballano

    07/10/2018, 3:19 PM
    the problem is that if you try to check from java:
    (1L as Any)::class.java.isAssignableFrom(Long::class.java)
    returns false
    i
    6 replies · 2 participants
Powered by Linen
Title
a

aballano

07/10/2018, 3:19 PM
the problem is that if you try to check from java:
(1L as Any)::class.java.isAssignableFrom(Long::class.java)
returns false
i

ilya.gorbunov

07/10/2018, 4:36 PM
If you want to use just java reflection, you have to consider corner cases like that.
With kotlin reflection (requires
kotlin-reflect
dependnecy) you can check
someLong::class.isSubclassOf(Long::class)
or vice versa.
a

aballano

07/11/2018, 11:03 AM
Hmm well with Java reflection I could understand that a java Long/long won't work in that case with a Kotlin Long
but this case seems like an optimization done by the compiler that is far from explicit
because this works
(1L)::class.java.isAssignableFrom(Long::class.java)
so I don't think is just a corner case
View count: 1