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

    ylemoigne

    02/28/2018, 12:08 PM
    Is there a form more idiomatic than other between
    someList.map(::Foo)
    and
    someList.map { Foo(it) }
    ?
    c
    s
    r
    • 4
    • 4
  • j

    janvladimirmostert

    02/28/2018, 4:19 PM
    There are #intellij and #intellij-plugins channels, not sure how active they are
    s
    • 2
    • 1
  • p

    poohbar

    02/28/2018, 4:48 PM
    @Hugo it blocks until the writing is finished, so any statement after this will be executed after the writing has been finished.
    h
    • 2
    • 3
  • a

    agrosner

    02/28/2018, 6:29 PM
    annotation processor is a separate configuration, kapt, which doesnt affect dex or android apk. only the code generatdd
    a
    • 2
    • 6
  • u

    ursus

    03/01/2018, 4:19 AM
    Hi, id like to ask, copy ctor from data classes, with default parameters used to only change one thing while keeping others .. how would one translate it to java?
    c
    • 2
    • 1
  • r

    ribesg

    03/01/2018, 7:42 AM
    Is there still no way to reload a file from disk in a run configuration in IntelliJ?
    k
    • 2
    • 1
  • h

    hhariri

    03/01/2018, 12:21 PM
    KotlinConf Super Early Bird and Workshop Tickets are now available. Heads-up that the number of tickets at this price are limited (as are the seats at the workshops) https://twitter.com/kotlinconf/status/969183192551960578
    :kotlin: 11
    💯 2
    👏 4
    m
    n
    o
    • 4
    • 7
  • a

    Arun

    03/01/2018, 2:36 PM
    Is there a good example on how to use
    buildString()
    ? https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/build-string.html
    d
    d
    r
    • 4
    • 6
  • l

    locke

    03/01/2018, 3:57 PM
    Didn't know if there was a more comprehensive one.
    k
    • 2
    • 1
  • j

    Joakim Fast

    03/01/2018, 4:33 PM
    Yes it is
    p
    • 2
    • 7
  • s

    Shawn

    03/01/2018, 5:44 PM
    surprised
    @kotlin
    hasn’t posted that yet
    c
    • 2
    • 1
  • b

    brabo-hi

    03/01/2018, 5:49 PM
    i love kotlin, i really really love kotlin...just started working on it since couple time, and it changed my life 🙂. I come from Java/Scala 😫 @. I have question. How do we deal with static variable in kotlin ?
    d
    s
    • 3
    • 2
  • p

    poohbar

    03/01/2018, 6:46 PM
    fun `hi hello`()
    The name of the function now has a suggestion on it: "Remove redundant back ticks". They are not redundant and the action does nothing. Could anyone confirm?
    :youtrack: 1
    b
    r
    • 3
    • 2
  • t

    tschuchort

    03/01/2018, 7:01 PM
    is there any way to get the default value of a parameter during annotation processing?
    s
    • 2
    • 2
  • v

    vlad

    03/01/2018, 9:30 PM
    is there some way to deal with the fact that kotlin methods can throw exceptions such as IOException that are “checked” exceptions in java without `throws`in teh signature?
    n
    s
    +3
    • 6
    • 9
  • j

    jtravis

    03/01/2018, 11:15 PM
    I would like to use
    when
    exhaustively when looking through some sealed classes, but there is no real result from each of the
    when
    clauses. The best I can currently do appears to be below:
    val someVariableThatDoesntDoAnything = when(some) {
            is FirstClass -> {} 
            is SecondClass -> {}
        }
    It seems like it would be nice to allow
    val _ = when(some) { ... }
    n
    d
    • 3
    • 2
  • j

    jermainedilao

    03/02/2018, 3:13 AM
    Hi! I’m trying to create a project following Clean Architechture. I’m already done setting up different modules. Including the “domain” module which is a pure java module (to make sure there’s no android components that will be used here). However during build time, It could not resolve the classes inside my “domain” module. What could be wrong here? here’s my dependencies inside my app build.gradle
    s
    • 2
    • 5
  • s

    sindrenm

    03/02/2018, 12:50 PM
    (That is, what's the difference between
    as? String
    and
    as String?
    ? 😒imple_smile:)
    d
    • 2
    • 10
  • a

    Andreas Sinz

    03/02/2018, 2:32 PM
    @Guillaume Imbert possibly something is cached. have you tried a full rebuild? if that doesnt help, maybe try to invalidate the cache of intellij
    ➕ 1
    g
    • 2
    • 3
  • o

    orangy

    03/02/2018, 4:42 PM
    We might need some minimal working (non-working) example to suggest anything
    z
    • 2
    • 7
  • y

    ylemoigne

    03/02/2018, 6:33 PM
    I have a java class
    Foo
    out of my control which has a method named
    div(Bar bar)
    ; Kotlin seems to allow the usage of this method as an
    operator
    . But this method, is not really what you can expect for a division. And I would like to implement the
    operator fun Foo.div(bar:Bar)=division(bar)
    to get the right action.... But as
    div
    exist, the extension is shadowed. I suppose I'm completely out of luck ? (No way to tell kotlin that the
    div()
    method in the class is not an operator method ?)
    e
    n
    • 3
    • 3
  • p

    patapon

    03/03/2018, 12:02 PM
    there is an interface called 'LocalRedeclarationChecker' that may be responsible for that, but I can't figure out where it is called for class members
    a
    • 2
    • 1
  • y

    ylemoigne

    03/03/2018, 5:02 PM
    It's strange to have to disable an inspection in idea to respect kotlin-coding-convention.... (
    Package name does not match containing directory
    vs
    In pure Kotlin projects, the recommended directory structure is to follow the package structure with the common root package omitted
    ). And is there a way to give IntelliJ the "base" package for new files under root ?
    g
    • 2
    • 1
  • t

    tipsy

    03/03/2018, 8:12 PM
    is
    by lazy
    supposed to work when calling from java?
    o
    • 2
    • 4
  • y

    ylemoigne

    03/03/2018, 8:15 PM
    Is there a list of forbidden characters in back-ticked method names ? (And if there is way to circumvent them, as I would like to put a
    /
    in it)
    c
    c
    • 3
    • 6
  • l

    liz3

    03/04/2018, 1:47 AM
    Can someone quickly help me? How exactly does the code looks for the kotlin class to act as a Controller for a JavaFX scene created by a .fxml file? Because in java you leave the variables undefined which will later be referred to the gui object by the fxml loader, now of course i cant leave the var undefined in kotlin. Java:
    @FXML
        private ListView<String> entriesList;
        @FXML
        private TextField hostField;
        @FXML
        private TextField nameField;
        @FXML
        private PasswordField passField;
        @FXML
        private TextField pathField;
        @FXML
        private Button testConnBtn;
        @FXML
        private Button saveBtn;
        @FXML
        private Button delBtn;
        @FXML
        private Button saveNewBtn;
        @FXML
        private TextField customPath;
        @FXML
        private ComboBox<String> typeBox;
    b
    r
    c
    • 4
    • 4
  • c

    cedric

    03/04/2018, 4:31 AM
    @Ruckus @orangy I'd phrase it this way:
    lateinit
    is very useful when your objects are being managed by a container, and containers typically separate object instantiation from object initializations. Some example containers would be Android, the servlet spec, and probably many others. Technically,
    lateinit
    has nothing to do with Java and nothing to do with dependency injection.
    r
    • 2
    • 2
  • k

    karelpeeters

    03/04/2018, 3:23 PM
    more values are of type
    Any
    compared to
    String
    But less values are of type
    (Any) -> Unit
    then of
    (String) -> Unit
    , so the former is more specific.
    a
    a
    • 3
    • 5
  • c

    CodeIsmail

    03/04/2018, 8:41 PM
    I'm trying to learn Kotlin using the kotlin-koan and I'm already disappointed with the process. So after cloning the repo, I get errors when running the test. I came across a possible solution stating to run :testClasses gradle task, After doing doing that, every test seem to be passing without solving any exercise. I'd appreciate guidance to setting it up.
    a
    • 2
    • 2
  • j

    jcminarro

    03/04/2018, 9:18 PM
    Hello, I have had confusion with
    when
    expresion and I would like to share with you and see what you think about it. I have created a repo that reproduces the problem that I had, you can check here: https://github.com/JcMinarro/SealedClass The problem was with some Sealed Class that has some
    object class
    . The IDE, when autocomplete the remaining branches, if some of the cases is an
    object class
    doesn't add the
    is
    operator at the beginning. I though that the operator
    is
    was redundant when it was used inside of
    when
    with an
    object class
    but It is not the same. I had the problem when I serialized/deserialized that
    object class
    and I could see that I got a
    kotlin.NoWhenBranchMatchedException
    a
    r
    • 3
    • 13
Powered by Linen
Title
j

jcminarro

03/04/2018, 9:18 PM
Hello, I have had confusion with
when
expresion and I would like to share with you and see what you think about it. I have created a repo that reproduces the problem that I had, you can check here: https://github.com/JcMinarro/SealedClass The problem was with some Sealed Class that has some
object class
. The IDE, when autocomplete the remaining branches, if some of the cases is an
object class
doesn't add the
is
operator at the beginning. I though that the operator
is
was redundant when it was used inside of
when
with an
object class
but It is not the same. I had the problem when I serialized/deserialized that
object class
and I could see that I got a
kotlin.NoWhenBranchMatchedException
a

Andreas Sinz

03/04/2018, 9:35 PM
is
compares the types, without
is
it checks whether its the same runtime-instance. if you serialize/deserialize an
object
, it is a new runtime instance
there was a youtrack issue somewhere about that
for now always use
is
when working with a
sealed class
j

jcminarro

03/04/2018, 9:37 PM
Yes, I know (Now). Without
is
it compare the value. I would like that IDE suggest you to use always
is
when you work with a
sealed class
Do you know where I could find the youtrack issue that you talk about?
a

Andreas Sinz

03/04/2018, 9:39 PM
https://youtrack.jetbrains.com/issue/KT-21570
👍 2
r

raulraja

03/04/2018, 10:03 PM
@Andreas Sinz regardless of the serialization issue, Is this related to Kotlin treating identifiers for the singleton type the same as the value it holds? In Scala there is a
MySingleton.type
explicit synthetic type to be able to refer to the types of singleton objects but in Kotlin we have ambiguity:
when (a) {
  is B -> // type comparison works for class an object
}
when (a) {
  B -> //ambiguos comparison equals based comparison takes precedence
}
Both case would compile fine but in the second one the semantics of the program change since when defaults matches to equals comparison.
in that program if
B
is a class it would be compared by type but if it's an object it would be compared against the object value and not the object type.
a

Andreas Sinz

03/05/2018, 8:40 AM
@raulraja yes, your second example is just a
a.equals(B)
where
B
is the "only" instance of
object B
your second example doesn't work if
B
is a class. You either need to use
is B ->
to compare the types or
B() ->
to compare with
equals
r

raulraja

03/05/2018, 10:36 AM
is that the case? It does compile and run but the semantics are wrong because
B ->
is valid for classes. If
B
was a class it would do a type comparison but if it's an object uses equals based comparison. You can see in @jcminarro repo how the test fails even compiling fine. If you add
is B ->
then it performs the right comparison. This is going to be confusing as it stands in Kotlin to many users and has the potnetial to introduce runtime woas and bugs because of ambiguity. Refactoring the class to an object is common and
when
cases left behind will still compile but yield a different behavior at runtime.
a

Andreas Sinz

03/05/2018, 11:07 AM
using
class B
,
B ->
does not compile here with the message:
Classifier 'B' does not have a companion object, and thus must be initialized here
. In his repo he has
SomeSealedClass.SomeObjectClass -> false
which is an object and
is SomeSealedClass.SomeDataClass -> true
which is a data class. I can't find any occurence of
SomeDataClass ->
without
is
in his tests
r

raulraja

03/05/2018, 11:40 AM
@Andreas Sinz my bad, the IDE fooled me.
View count: 2