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

    Hexa

    07/17/2018, 6:14 PM
    I got a code that looks like this:
    import com.fasterxml.jackson.databind.ObjectMapper
    
    fun main ( args : Array < String > ) {
    
        val mapper = ObjectMapper()
        val jsonResult = mapper.writerWithDefaultPrettyPrinter()
                .writeValueAsString(someString)
    
        System.out.println("blank: ${jsonResult.isBlank()}")
        System.out.println("isEmpty: ${jsonResult.isEmpty()}")
        System.out.println("{}: ${jsonResult.contentEquals("{}")}")
    
    
    
    }
    jsonResult
    returns
    {}
    in my logs which means its a an empty json. How do I check if jsonResult is equals to
    {}
    (or empty). All of my println returns
    false
    , so
    isEmpty
    and
    isBlank
    dont work.
    n
    • 2
    • 3
  • e

    elect

    07/18/2018, 8:45 AM
    I'm running 1.2.51, is this the problem? Will an eap solve the problem?
    g
    • 2
    • 11
  • a

    Ayden

    07/18/2018, 10:02 AM
    @Can Orhan I believe the #android channel is suitable to ask the question about Android Kotlin. But my question is more about Retrofit 2 and Moshi.
    g
    • 2
    • 2
  • a

    Ayden

    07/18/2018, 10:36 AM
    I saw there is a library call
    instanceof
    , but I don't think it can be use like
    typeof
    👏 1
    d
    • 2
    • 1
  • h

    Hexa

    07/18/2018, 11:46 AM
    Does anyone know how to remove an attribute from JSON using jackson ObjectMapper? https://stackoverflow.com/q/51401195/9992516
    :stackoverflow: 1
    k
    • 2
    • 1
  • a

    aerb

    07/18/2018, 6:50 PM
    If not, I think this would be a good feature to meet parity with the Java
    Files
    implementation. Behaviour can stay the same, but accept an option to change behaviour.
    k
    • 2
    • 1
  • j

    Jonathan Walsh

    07/19/2018, 12:38 AM
    If I have a bunch of operations on a Sequence<Long>, is each step unboxing and boxing the value? Or is a primitive long being passed through each step? For example
    sequenceOf(1L, 2L, 3L).map { it + 1L }.forEach { println(it) }
    k
    • 2
    • 1
  • j

    Jiddles

    07/19/2018, 2:03 PM
    Hi guys, this one keeps coming regularly for me Is there a nice way of dealing with this ? I saw the SO about it but wasn’t great.
    // The below code results in a compilation error
    data class ViewModel(
        var lineSpeed: Int? = null
    )
    
    val viewModel = ViewModel()
    
    if(viewModel.lineSpeed != null && viewModel?.lineSpeed > 0 ) {}
    
    //Error : Smart cast to 'Int' is impossible, because 'viewModel.lineSpeed' is a mutable property that could have been changed by this time
    l
    a
    +2
    • 5
    • 6
  • a

    arekolek

    07/19/2018, 3:54 PM
    isn't that function just
    fun <K, V> Map<K, V?>.filterValuesNotNull() = filterValues { it != null } as Map<K, V>
    ? I'm not sure I would even define it at all
    p
    k
    • 3
    • 6
  • r

    redrield

    07/19/2018, 11:07 PM
    I'm trying to set up an environment to contribute to kotlin, i have jdk 6-9 installed, and I have these lines in the gradle.properties
    JDK_16="C:\\Program Files\\Java\\jdk1.6.0_45"
    JDK_17="C:\\Program Files\\Java\\jdk1.7.0_80"
    JAVA_HOME="C:\\Program Files\\Java\\jdk1.8.0_172"
    JDK_9="C:\\Program Files\\Java\\jdk-9.0.4"
    but when I try to import gradle project in intellij it says that JDK_16 isn't a valid jdk home path
    i
    • 2
    • 1
  • r

    redrield

    07/19/2018, 11:13 PM
    Ah, I think it was because of the quotes
    s
    i
    • 3
    • 4
  • k

    kango_v

    07/20/2018, 12:55 PM
    newbie to kotlin..... Anyone using Kotlin in Eclipse? Or am I the only insane person here?
    p
    j
    • 3
    • 2
  • k

    kango_v

    07/20/2018, 12:56 PM
    reason is that we have current Java projects that i'd like to start slowly migrating.
    s
    c
    d
    • 4
    • 3
  • s

    Slackbot

    07/20/2018, 3:13 PM
    This message was deleted.
    :google: 1
    s
    a
    • 3
    • 2
  • d

    dsavvinov

    07/20/2018, 4:31 PM
    See this discussion https://kotlinlang.slack.com/archives/C0922A726/p1521649327000400
    👍 1
    k
    • 2
    • 1
  • s

    Slackbot

    07/20/2018, 6:26 PM
    This message was deleted.
    s
    y
    k
    • 4
    • 9
  • s

    Slackbot

    07/20/2018, 7:38 PM
    This message was deleted.
    k
    n
    • 3
    • 2
  • s

    skennedy

    07/20/2018, 7:47 PM
    Is there any way I can make this work so that anyone accessing
    name
    on
    B
    gets a
    String
    instead of
    String?
    ?
    open class A(val name: String?)
    class B(name: String) : A(name)
    fun findName(b: B): String = b.name // errors because `b.name` is `String?`
    f
    • 2
    • 3
  • d

    Diefferson

    07/21/2018, 6:14 PM
    Hello Everyone, Someone here work with education or is a professor of technology?
    a
    • 2
    • 4
  • u

    Udit003

    07/22/2018, 11:20 AM
    package com.classLesson sealed class Person { // why compiler is complaining here class Men : Person() class Women : Person() abstract fun Sexuality() : String } class Men : Person() { override fun Sexuality(): String { return "M" } } class Women : Person() { override fun Sexuality(): String { return "F" } } // compiler should complain for this class Animal : Person() { override fun Sexuality(): String { return "shouldn't be allowed" } } fun main(args: Array<String>) { var a: Person = Animal() when (a) { is Men -> println("Men") is Animal -> println("Animal") } } @
    a
    • 2
    • 13
  • d

    Dennis Cornwell

    07/22/2018, 5:40 PM
    Is this the right place to discuss pull requests to the Kotlin code base? The GitHub repo mentions using the #kontributors channel, but I don't see that active at the moment
    g
    • 2
    • 2
  • m

    Marcus Fihlon

    07/23/2018, 3:05 PM
    Does anybody know who is responsible for the https://kotlin.link/ website? There is no contact form or imprint and I “fixed” 11 issues from the GitHub issue tracker and now I’m waiting since two weeks for the PR to be merged…
    s
    t
    • 3
    • 4
  • s

    Slackbot

    07/23/2018, 5:15 PM
    This message was deleted.
    :google: 9
    :stackoverflow: 6
    r
    • 2
    • 1
  • u

    user

    07/24/2018, 7:11 AM
    message has been deleted
    🤔 5
    n
    • 1
    • 1
  • v

    vpriscan

    07/24/2018, 9:03 AM
    anyone got any fresh kotlin vs java runtime benchmark?
    g
    k
    c
    • 4
    • 12
  • j

    Jamie Lynch

    07/24/2018, 1:08 PM
    Something a bit different from usual - I'm hoping to start a contest where the aim is to write the most convoluted Kotlin code possible, in order to pass what would otherwise be a fairly simple problem. If you've ever seen the Obfuscated C code contest, it would be sort of similar to that, but with all the wonderful possibilities that things like extension functions and operator overloads allow. I've started it off with a Hello World challenge, would anyone be interested in having a go? https://github.com/fractalwrench/iokk
    😃 2
    🤔 1
    s
    • 2
    • 3
  • w

    warriorprincess

    07/24/2018, 3:25 PM
    fun findCombs(res: List<String>, digis: List<Int>) : List<String> = if (digitss.isEmpty()) res 
            else for (letter in map[digis[0]]) findCombs(res + letter, digis.subList(1, digis.lastIndex))
    r
    a
    • 3
    • 52
  • j

    janos

    07/24/2018, 5:51 PM
    I guess withContext has to be a function which get a lambda function as param, but the concrete implementation is not clear
    l
    k
    • 3
    • 66
  • j

    Janar

    07/24/2018, 5:52 PM
    Hi, I am writing webapp with Kotlin on JVM (api + html) and was using kotlinx.html to generate HTML. But JS in HTML is not type checked. I was wondering if there is a better way to generate kotlin to JS along with kotlinx.html. I would think js could be generated before hand from kotlin in “generate-sources” step and kotlinx.html can somehow use it…!?
    n
    • 2
    • 1
  • e

    elect

    07/24/2018, 5:55 PM
    So, I have the following:
    if (io.imeSetInputScreenPosFn != null && (g.platformImePos - g.osImePosSet).lengthSqr > 0.0001f)
                io.imeSetInputScreenPosFn(g.platformImePos.x.i, g.platformImePos.y.i) // error, Reference has a nullable type
    where
    val imeSetInputScreenPosFn: ((x: Int, y: Int) -> Unit)?
    But I should profit from the smart cast from the
    if
    that ensures it's not null
    r
    k
    • 3
    • 19
Powered by Linen
Title
e

elect

07/24/2018, 5:55 PM
So, I have the following:
if (io.imeSetInputScreenPosFn != null && (g.platformImePos - g.osImePosSet).lengthSqr > 0.0001f)
            io.imeSetInputScreenPosFn(g.platformImePos.x.i, g.platformImePos.y.i) // error, Reference has a nullable type
where
val imeSetInputScreenPosFn: ((x: Int, y: Int) -> Unit)?
But I should profit from the smart cast from the
if
that ensures it's not null
r

rook

07/24/2018, 6:04 PM
I’m assuming
imeSetInputScreenPosFn
is a
var
, so the compiler (correctly) thinks that it can become null if there’s an asynchronous operation that changes it.
e

elect

07/24/2018, 6:04 PM
no, it's a
val
, that's the problem..
r

rook

07/24/2018, 6:06 PM
Ah, I just read the first block and didn’t read the rest, sorry about that..
e

elect

07/24/2018, 6:06 PM
np
r

rook

07/24/2018, 6:08 PM
Wait, is
io
nullable?
e

elect

07/24/2018, 6:08 PM
neither
wait
no, it's not, confirmed
k

karelpeeters

07/24/2018, 6:52 PM
The compiler doesn't realize that
io.imeSetInputScreenPosFn
isn't null, where both
io
and
imeSetInputScreenPosFn
are `val`s?
r

rook

07/24/2018, 7:52 PM
That’s what he’s saying
k

karelpeeters

07/24/2018, 8:26 PM
That doesn't sound right to me:
class Test(val str: String?)
val test = Test("hey")

test.str.toUpperCase()      //not allowed
if (test.str != null)
    test.str.toUpperCase()  //allowed
e

elect

07/24/2018, 8:30 PM
io
is a
var
, but is not nullable
k

karelpeeters

07/24/2018, 8:34 PM
Then of course that isn't allowed, the
io
reference could have changed between the check and the indexing.
r

rook

07/24/2018, 9:29 PM
class SomeClass(val str: String?)
var test = SomeClass("yo")

fun main() {
    test.str.toUpperCase() //Only safe calls etc. (use ?.)

    if(test.str != null) {
        test.str.toUpperCase() //Smart cast to String is impossible, because 'test.str' is a complex expression
    }
}
k

karelpeeters

07/24/2018, 9:30 PM
Because test is a
var
. Make it a
val
and it'll work.
r

rook

07/24/2018, 9:31 PM
Yeah, was just clarifying the error for posterity. The original message made it seem like the smart cast had unexpected behavior, but it’s not unexpected.
k

karelpeeters

07/24/2018, 9:32 PM
Ah okay, thanks!
e

elect

07/25/2018, 7:26 AM
yeah, that makes sense, thanks guys and sorry for the trouble
r

rook

07/25/2018, 3:35 PM
No trouble at all, friend
👍 1
View count: 1