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

    kevinmost

    09/19/2017, 9:53 PM
    it's just a matter of the order of operations being different from what you expected. There's no bug here, though it's definitely a gotcha and I think a lint check would be great
    a
    • 2
    • 2
  • k

    kevinmost

    09/19/2017, 10:03 PM
    and there should be a lint check to warn you that this might not mean what you think it does
    👍 2
    k
    • 2
    • 1
  • s

    svenjacobs

    09/20/2017, 7:59 AM
    Hi, I want to map an enum class like
    enum class Status { OK, FAILED }
    to a JSON response (with Moshi). Unfortunately the JSON values are written in lower case like “ok” or “failed” and it’s not possible to overwrite the enum classes’ values. Any chances this is somehow possible or do I have to write a custom Moshi adapter?
    j
    • 2
    • 3
  • j

    jw

    09/20/2017, 1:44 PM
    https://kotlinlang.org/docs/reference/typecasts.html#is-and-is-operators
    b
    • 2
    • 1
  • w

    wineluis

    09/20/2017, 2:38 PM
    you can do [ "loL" ] in annotations instead of arrayOf("lol")
    👍 1
    k
    • 2
    • 1
  • j

    jkbbwr

    09/20/2017, 4:34 PM
    e.g.
    thing {
        a = "test"
        b = "wat"
    }
    d
    s
    • 3
    • 15
  • b

    bdawg.io

    09/21/2017, 6:16 AM
    I’m not suggesting that the compiler should do anything different if you’re explicitly defining a property as a different type. But my question isn’t about defining 2 properties as
    Any
    and expecting it to find the equals of the assigned type instead of the defined type
    g
    • 2
    • 2
  • g

    gildor

    09/21/2017, 7:07 AM
    So this is not a real “equals” and will not be used by system. Of course, you can use it manually, but for example HashMap or other system code just ignores these methods You can do the same thing in Kotlin, but of course it’s not correct convention for equals
    u
    b
    k
    • 4
    • 16
  • d

    diesieben07

    09/21/2017, 7:33 AM
    It also just does not work. You cannot "override" member functions with extension functions. If you use the
    ==
    it will never call an extension function (same if you call
    equals
    directly), since the
    equals
    in
    Any
    always has higher precedence.
    b
    u
    j
    • 4
    • 22
  • b

    bdawg.io

    09/21/2017, 8:01 AM
    Sorry for this conversation dragging in #general. A thread in #codingconventions would’ve probably been more appropriate
    g
    • 2
    • 2
  • c

    Czar

    09/21/2017, 8:09 AM
    After replacing kotlin-compiler with kotlin-compiler-embeddable guava problem went away:
    compile "org.jetbrains.kotlin:kotlin-script-util:$kotlinVersion", {
    	exclude module: 'kotlin-compiler'
    }
    compile "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion"
    Now application compiles, but does not start, because kotlin-compiler-embeddable bundles xmlpull which clashes with xstream dependency which we use in the app:
    org.xmlpull.v1.XmlPullParserException: No valid parser classes found in resource /META-INF/services/org.xmlpull.v1.XmlPullParserFactory that contained 'org.xmlpull.mxp1.MXParserFactory'
    I'm abandoning the experiment. Seems embedding kotlin scripting in a serious real-world application is impossible at this point and we'll have to stick with Groovy. 😢
    i
    • 2
    • 1
  • c

    Czar

    09/21/2017, 11:09 AM
    It is probably unintuitive from java convert's point of view, but it is logical, constructor is a function with the same name as the class, so
    ::StringBuilder
    is the reference to that function.
    b
    d
    • 3
    • 3
  • j

    jstuyts-squins

    09/21/2017, 12:42 PM
    I think Kotlin sees the former as, i.e. as 2 declarations: companion object without members and a property:
    companion object
    val yo = "yo"
    u
    • 2
    • 3
  • g

    gjesse

    09/22/2017, 3:27 AM
    i feel like this should work, but i get “Type inference failed - required
    List<List<String>>
    , found
    List<Any>
    kotlin
        val hmm: List<List<String>> = listOf(
                listOf("a"),
                listOf("b")
        )
        val hmm2: List<List<String>> = hmm + listOf("c")
    e
    k
    • 3
    • 12
  • l

    louiscad

    09/22/2017, 11:48 AM
    Kotlin 1.1.50 is coming! :kotlin-flag: 👌🏽
    m
    s
    • 3
    • 4
  • k

    karelpeeters

    09/22/2017, 12:39 PM
    Yes, that's a bug, create an issue for it on YouTrack.
    m
    • 2
    • 1
  • m

    morozov

    09/22/2017, 3:44 PM
    Can i modified this fun in something more sweet:
    private fun processStickyEvents() {
            EventBus.getDefault().getStickyEvent(AccountsSelectEvent::class.java)?.let { onAccountsSelectEvent(it)  }
            EventBus.getDefault().getStickyEvent(CategoriesSelectEvent::class.java)?.let { onCategoriesSelectEvent(it)  }
            EventBus.getDefault().removeStickyEvent(AccountsSelectEvent::class.java)
            EventBus.getDefault().removeStickyEvent(CategoriesSelectEvent::class.java)
        }
    mb something like this?
    private fun processStickyEvents(Class.name, lambda) {
    l
    • 2
    • 1
  • t

    trevjones

    09/22/2017, 4:23 PM
    currently it looks something like
    fun <T: Any> getStickyEvent(type: Class<T>): T?
    you can make it reified
    inline fun <reified T: Any> getStickyEvent(): T?
    then you can use
    T::class.java
    as your replacement for the
    type
    argument you used before
    🙃 1
    m
    • 2
    • 1
  • p

    purereborn

    09/22/2017, 6:25 PM
    @kevinmost @anthonycr here's what I came up with: lines being lines of text:
    return lines.collect(CustomCollector)
                    .flatMap { x -> process(x)}....
    It uses a CustomCollector
    object CustomCollector : Collector<String, MutableList<MutableList<String>>, MutableList<MutableList<String>>> {
        override fun accumulator(): BiConsumer<MutableList<MutableList<String>>, String> {
            return CustomBiConsumer() // main logic here, looks for a specific line, creates a new MutableList<String> and append it to the List of Lists, otherwise add non-empty lines to the last List of strings
        }
    
        override fun combiner(): BinaryOperator<MutableList<MutableList<String>>> {
            return CustomBinaryOperator() // combines 2 Mutable list of lists
        }
    
        override fun characteristics(): MutableSet<Collector.Characteristics> {
            return Collections.singleton(Collector.Characteristics.IDENTITY_FINISH) //the accumulator object is the same as the result object 
        }
    
        override fun supplier(): Supplier<MutableList<MutableList<String>>> {
            return ArrayListSupplier() //creates a new Muttable list of strings
        }
    
        override fun finisher(): Function<MutableList<MutableList<String>>, MutableList<MutableList<String>>> {
            return Function.identity() // noop 
        }
    
    }
    
    class CustomBinaryOperator : BinaryOperator<MutableList<MutableList<String>>> {
        override fun apply(t: MutableList<MutableList<String>>,
                u: MutableList<MutableList<String>>): MutableList<MutableList<String>> {
            t.addAll(u)
            return t
        }
    }
    
    class CustomBiConsumer : BiConsumer<MutableList<MutableList<String>>, String> {
        override fun accept(stringGroups: MutableList<MutableList<String>>, line: String) {
            if (line.isEmpty()) return
            if (line.matches(MacParser.NAME_REGEX)) {
                stringGroups.add(ArrayList())
            }
    
            stringGroups.last().add(line)
        }
    }
    
    class ArrayListSupplier : Supplier<MutableList<MutableList<String>>> {
        override fun get(): ArrayList<MutableList<String>> {
            return ArrayList()
        }
    }
    :java: 1
    i
    • 2
    • 3
  • k

    kovrik

    09/22/2017, 8:06 PM
    Has anybody tried 1.1.50 already? It doesn’t work for me 😞 Getting the following error when trying to run app from Intellij: java.lang.NoClassDefFoundError: Could not initialize class org.jetbrains.jps.incremental.BuilderRegistry$Holder Tried to disable incremental compilation, tried to invalidate caches, but in vain.
    i
    • 2
    • 1
  • d

    diesieben07

    09/22/2017, 8:46 PM
    You can actually do this in Kotlin:
    fun <T> castUnsafe(input: Any?) = input as T
    // later:
    thisMethodHasNonNullParameter(castUnsafe(null))
    Will compile and fail at runtime with
    IllegalArgumentException
    thrown from
    thisMethodHasNonNullParameter
    .
    i
    • 2
    • 2
  • e

    elect

    09/23/2017, 6:26 PM
    I have several objects to reinterpreter memory:
    interface reinterpreter<T> {
        operator fun get(index: Int): T
        operator fun set(index: Int, value: T): Any
    }
    object vec1bData : reinterpreter<Vec1b> {
        override operator fun get(index: Int) = Vec1b(data, index * Vec1b.size)
        override fun set(index: Int, value: Vec1b) = <http://value.to|value.to>(data, index * Vec1b.size)
    }
    but when I type
    inline fun <reified T> data():reinterpreter<T> = when (T::class.java) {
            Vec1b::class.java -> vec1bData
    }
    I get:
    required
    reinterpeter<T>
    , but found
    vec1bData
    i
    • 2
    • 3
  • k

    karelpeeters

    09/23/2017, 8:28 PM
    Is there a
    1.1.50
    version of the Kotlin plugin and how do I get it? Idea is complaining about binary incompatibilities, and the auto updater doesn't see the update because the current version is
    1.2-M2-release-IJ2017.2-1
    and that's considered a higher version.
    j
    i
    • 3
    • 6
  • e

    eygraber

    09/24/2017, 6:02 AM
    Is there a reason to use incremental compilation on CI, or is it pointless since it does a clean build every time? Is there a way to disable it (using Gradle)?
    d
    d
    • 3
    • 3
  • y

    yoavst

    09/24/2017, 11:38 AM
    fun main(args: Array<String>) {
        for (mx in -100L..100) {
            println(mx)
        }
    }
    Does it crash compiler only for me on 1.1.50?
    i
    • 2
    • 1
  • k

    karelpeeters

    09/24/2017, 5:19 PM
    @mingkangpan What version of Kotlin are you on? I think this was fixed a while ago.
    m
    • 2
    • 5
  • f

    feroz_baig

    09/24/2017, 7:39 PM
    upgraded kotlin to 1.1.50-release-Studio3.0-1 getting this error :
    Error:Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.50-release-Studio3.0-1.
    Searched in the following locations:
        file:/opt/android-studio-preview/gradle/m2repository/org/jetbrains/kotlin/kotlin-gradle-plugin/1.1.50-release-Studio3.0-1/kotlin-gradle-plugin-1.1.50-release-Studio3.0-1.pom
        file:/opt/android-studio-preview/gradle/m2repository/org/jetbrains/kotlin/kotlin-gradle-plugin/1.1.50-release-Studio3.0-1/kotlin-gradle-plugin-1.1.50-release-Studio3.0-1.jar
        <https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.1.50-release-Studio3.0-1/kotlin-gradle-plugin-1.1.50-release-Studio3.0-1.pom>
        <https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.1.50-release-Studio3.0-1/kotlin-gradle-plugin-1.1.50-release-Studio3.0-1.jar>
        <https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.1.50-release-Studio3.0-1/kotlin-gradle-plugin-1.1.50-release-Studio3.0-1.pom>
        <https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.1.50-release-Studio3.0-1/kotlin-gradle-plugin-1.1.50-release-Studio3.0-1.jar>
    Required by:
        project :
    t
    • 2
    • 2
  • e

    elect

    09/24/2017, 8:49 PM
    has anyone ever hit
    Error:Kotlin: [Internal Error] java.lang.RuntimeException: Error generating class file gli_/coreTexture1d$5.class (compiled from [C:\Users\elect\IdeaProjects\gli\src\test\kotlin\gli_\coreTexture1d.kt]): Method code too large!
    ? Coz I don't think it is too large..
    :youtrack: 1
    • 1
    • 1
  • o

    Oleksii

    09/24/2017, 9:03 PM
    Hey, fellow developers! This week I wanted to create a small tutorial about getting started with Kotlin and it ended up being the size of e-book. It is about Kotlin and how to get started with kotlin. It features setting up of all the dependencies, learning how to create new kotlin project in IntelliJ and building a few features for the command-line application. The tutorial itself is targeted at beginner programmers, but I would love to get some input from more experienced developers too. Here is the link: https://iwillteachyoukotlin.com And the tutorial has a projected trajectory at the end so that I can continue creating the content (implement more features for the app) in form of blog post (or a course) for the same website, including expanding on different platforms, such as Web development with Kotlin and Android development with Kotlin. As always, feedback is warmly welcome as well, as shares on social networks, hacker news, reddit, etc (in case you liked it 😉 ).
    k
    v
    • 3
    • 19
  • k

    kovrik

    09/25/2017, 4:01 AM
    clean install doesn’t help, invalidating intellij caches doesn’t help, deleting the whole caches dir doesn’t help.
    d
    n
    • 3
    • 3
Powered by Linen
Title
k

kovrik

09/25/2017, 4:01 AM
clean install doesn’t help, invalidating intellij caches doesn’t help, deleting the whole caches dir doesn’t help.
d

dawidhyzy

09/25/2017, 5:13 AM
plugin updated also?
n

napperley

09/25/2017, 7:03 AM
kovrik - If you use Gradle then downgrading Kotlin to 1.1.4-3 might resolve your issue.
Does the issue have something to do with invalid compiler version metadata?
View count: 2