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

    jlleitschuh

    09/26/2018, 8:13 PM
    Interesting Bug I just discovered. If you have
    -Xjsr305=strict
    enabled and you have a java class annotated with:
    @ParametersAreNonnullByDefault
    . If that class overrides
    equals(Object other)
    without having
    @Nullable
    on the
    other
    param, kotlin can't use the
    ==
    operator. Eg. The following won't compile:
    JavaSomething("one") == JavaSomething( "one")
    Java side:
    @ParametersAreNonnullByDefault
    public class JavaSomething {
    
        private final String something;
    
        JavaSomething(String something) {
            this.something = something;
        }
    
        @Override
        public boolean equals(final Object other) {
            if (this == other) return true;
            if (other == null) return false;
            if (this.getClass() != other.getClass()) return false;
            final JavaSomething javaOther = (JavaSomething) other;
            return something.equals(javaOther.something);
        }
    }
    a
    d
    17 replies · 3 participants
  • t

    Tsvetozar Bonev

    09/27/2018, 7:33 AM
    Any of you have any experience with ktor.io and Spark Java? Does ktor have filters, I can't find any in the documentation.
    g
    m
    2 replies · 3 participants
  • r

    ribesg

    09/27/2018, 8:33 AM
    What would be the channel to talk about
    build.gradle.kts
    ?
    e
    1 reply · 2 participants
  • v

    vaskir

    09/27/2018, 9:45 AM
    so local functions cannot be recursive?
    d
    a
    +3
    57 replies · 6 participants
  • v

    vaskir

    09/27/2018, 10:23 AM
    ok, another question: how do you guys implement FSMs?
    g
    3 replies · 2 participants
  • v

    vaskir

    09/27/2018, 10:45 AM
    @robin it compiles, but is it tail call optimized?
    a
    r
    +1
    9 replies · 4 participants
  • v

    vaskir

    09/27/2018, 11:21 AM
    is it possible to match like this?
    when (x) { is Foo && x.aFooField > 10 -> ... }
    a
    3 replies · 2 participants
  • v

    vaskir

    09/27/2018, 12:16 PM
    no
    catch (e: MyException if e.foo = 25) { .. }
    ??
    r
    12 replies · 2 participants
  • h

    Hamza

    09/27/2018, 2:22 PM
    anyone aware the font that was used to create the “kotlin” logo (not the colorful K, the whole word, like here :
    i
    2 replies · 2 participants
  • k

    karelpeeters

    09/27/2018, 5:25 PM
    Sure, it may work fine in some cases. And then in others it doesn't, eg.
    data class Foo(var x: Int)
    
    fun main(args: Array<String>) {
        val f = Foo(3)
        val s = mutableSetOf(f)
        f.x = 7
        println(s == setOf(Foo(7)))
    }
    on try.kotlinlang.org.
    a
    p
    +1
    20 replies · 4 participants
  • j

    JT

    09/27/2018, 11:19 PM
    I'm seeing something really weird. If I declare a var and set it to a declared constant value to initialize it, when I change it (in a overriden method called by the superclass's constructor) I see the value change, yet when I access the value later it seems to have been reset back to the constant. companion object { private const val DEFAULT_MAX_COLLAPSED_LINES = 3 } private var collapsedMaxLines: Int = DEFAULT_MAX_COLLAPSED_LINES ... In method called in constructor: collapsedMaxLines = 5 ... when I later access collapsedMaxLines it's 3 again. If I initialize to a number like 0, it gets the change, but when I used the declared constant in the companion (edit: or any non-zero value it appears), it seems to always revert back to the constant - is this a bug?
    o
    6 replies · 2 participants
  • p

    pavel

    09/27/2018, 11:38 PM
    I would guess that you are making wrong assumptions of the evaluation order
    :yes: 1
    j
    o
    2 replies · 3 participants
  • r

    ribesg

    09/28/2018, 8:30 AM
    New plugin update? Is Kotlin 1.3.0-rc-116 an RC2? Updated to rc-116, everything works great 👍
    e
    9 replies · 2 participants
  • m

    marcinmoskala

    09/28/2018, 10:17 AM
    Why vararg Nothing is forbidden?
    c
    j
    +2
    15 replies · 5 participants
  • n

    Nikky

    09/28/2018, 11:38 AM
    why use Nothing though.. whats the usecase ?
    i
    1 reply · 2 participants
  • p

    pp.amorim

    09/28/2018, 1:29 PM
    @jw Any idea when okhttp will move to okio >= 2.0? I want to get rid of the java source asap
    r
    g
    3 replies · 3 participants
  • b

    bdawg.io

    09/28/2018, 9:53 PM
    What would be the best way to pragmatically get the latest stable version number for Kotlin?
    m
    k
    +1
    9 replies · 4 participants
  • a

    Allan Wang

    09/29/2018, 1:00 AM
    Is it possible to take in a lambda that is based around generics? For example, can we simplify the following:
    enum class Order {
       ASCENDING {
           override fun <T : Comparable<T>> sort(iterable: Iterable<T>): List<T> =
                   iterable.sorted()
       }, DESCENDING {
           override fun <T : Comparable<T>> sort(iterable: Iterable<T>): List<T> =
                   iterable.sortedDescending()
       };
    
       abstract fun <T : Comparable<T>> sort(iterable: Iterable<T>): List<T>
    }
    Such that it is something in the form of
    enum class Order(...) {
      ASCENDING(::sorted), DESCENDING(::sortedDescending)
    }
    v
    3 replies · 2 participants
  • j

    jo

    09/29/2018, 3:23 PM
    Well this is nostalgic. I've got a defined grammar and was wondering if there's a recommended Kotlin library that will build the AST from the definition and an input string.
    2 replies · 1 participant
  • h

    Hexa

    09/29/2018, 4:53 PM
    yes in fact my class does make network calls/read disk
    k
    2 replies · 2 participants
  • h

    Hexa

    09/29/2018, 5:40 PM
    @karelpeeters thanks my main problem is that
    fun processIncomingMessages(incomingMessage: List<IncomingMessage>)
    is actually a function that thats a list of
    SomeOtherType
    but not
    IncomingMessage
    .
    SomeOtherType
    is just a json message, so I need to process each json message and wrap them in a IncomingMessage class. So it's actually look more like this this ( I try to use jacksonmapper library)
    // example incoming messages:
        //  {"message":"message1", phoneType":"iPhoneX", "test1"},
        //  {"message":"message1", phoneType":"Samsung1", "test2"}
    
        fun processIncomingMessages(incomingMessage: List<SomeType>): Map<MessageIndex, List<Message>>{
    
    
          //how do  I need to process each incoming json messsage and wrap them in IncomingMessage class?
            return incomingMessage.forEach {
    
                              val eventObj = jacksonObjectMapper().readValue(String(it.data.array()), IncomingMessage::class.java)
    
            }
    k
    5 replies · 2 participants
  • c

    cygnus

    09/30/2018, 5:34 AM
    not a question, rather a highlighting of the fun of kotlin:
    l
    h
    4 replies · 3 participants
  • a

    Abdelkrim

    09/30/2018, 2:13 PM
    Hi community I am new here , any advice before begining kotlin journey
    h
    m
    3 replies · 3 participants
  • m

    muralimohan962

    09/30/2018, 2:22 PM
    data class Person(val name: String, var age: Int) fun main() { val person1 = Person("Murali", 21) val person2 = person1.copy() } Now my question is do the fields in both person1 and person2 refer to the same objects? I mean person1.age === person2.age ?
    h
    k
    +1
    18 replies · 4 participants
  • a

    Antero Duarte

    10/01/2018, 12:27 PM
    Hey there, I've been messing with kotlin trying to create a class that will be used by an Apache Spark enabled application. so previously I had a class that had a method:
    override fun getFiles(path: String, sc: SparkContext): RDD<*> {
            sc.hadoopConfiguration().set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem::class.java.name)
            return sc.binaryFiles(path, 1)
        }
    And that was fine, It all worked properly. But now I had to add a .filter() to that returning RDD, and I'm struggling to get the code to compile, even though I don't get any errors in the IDE The smallest example I can give is:
    override fun getFiles(path: String, sc: SparkContext): RDD<*> {
            sc.hadoopConfiguration().set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem::class.java.name)
            return sc.binaryFiles(path, 1).filter { true }
        }
    Which should just return true from the filter and not do anything But I get this error when trying to build:
    Error:(56, 47) Kotlin: Type mismatch: inferred type is () -> Boolean but Function1<Tuple2<String!, PortableDataStream!>!, Any!>! was expected
    The closest I have got to making it work was:
    override fun getFiles(path: String, sc: SparkContext): RDD<*> {
            sc.hadoopConfiguration().set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem::class.java.name)
            return sc.binaryFiles(path, 1).filter(getFilterFunction())
        }
    
        private fun getFilterFunction(): scala.Function1<Tuple2<String, PortableDataStream>, Any> {
            return Function1<Tuple2<String, PortableDataStream>, Any> { tuple: Tuple2<String, PortableDataStream> ->
                return@Function1 true
            }
        }
    But I get
    Error:(60, 16) Kotlin: Interface Function1 does not have constructors
    Does anyone have experience with interfacing with Apache Spark from kotlin?
    o
    k
    8 replies · 3 participants
  • b

    Benoît

    10/01/2018, 1:26 PM
    Hey guys, I've been using kts scratches file for a while in Intellij CE and Android Studio and everything used to work perfectly. However since I had to delete my
    ~/.gradle/caches
    , scripts don't work anymore if I try to run them from the IDE I get this :
    Primary constructor not found for script template class ScriptTemplateWithArgs
    Any idea how to fix that ?
    a
    1 reply · 2 participants
  • d

    deviant

    10/01/2018, 2:34 PM
    why
    inline
    classes allow only one constructor param? it would be nice to have
    inline class Pair
    to avoid extra allocations
    a
    d
    9 replies · 3 participants
  • j

    jlleitschuh

    10/01/2018, 7:50 PM
    Is there some publicly published way to kill the kotlin compiler daemon?
    g
    1 reply · 2 participants
  • g

    groostav

    10/01/2018, 10:05 PM
    Alright so, its also the case that if A depends on B statically, and B encounters an exception in its static initializer, and the runtime calls
    A.main
    as its entry point, the only thing you'll see is
    NoClassDefFoundError: Cannot find 'com.you.A'
    correct? without a caused-by
    ExceptionInInitializer
    ?
    k
    1 reply · 2 participants
  • j

    Jukka Siivonen

    10/02/2018, 7:16 AM
    Correct, what I actually have is this list initialization which of course happens outside of the constructor of MyClass
    k
    7 replies · 2 participants
Powered by Linen
Title
j

Jukka Siivonen

10/02/2018, 7:16 AM
Correct, what I actually have is this list initialization which of course happens outside of the constructor of MyClass
k

karelpeeters

10/02/2018, 7:16 AM
Can you show the code?
j

Jukka Siivonen

10/02/2018, 7:27 AM
sure
something like
class MyClass (
    private val transitions: List<Transition> = listOf(

        Transition(Pair(Status.X, Status.Y),
            beforeTransition = asList(this::fun1),
            afterTransition = asList()
        ),
...
k

karelpeeters

10/02/2018, 7:30 AM
And that doesn't compile?
j

Jukka Siivonen

10/02/2018, 7:31 AM
no, it says 'this' is not defined in this context
using private var transitions: List<Transition> and init { transitions = listOf(...) } of course works fine with this::fun1
k

karelpeeters

10/02/2018, 12:00 PM
That's really strange, I'll experiment a bit later today.
View count: 2