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

    Animesh Sahu

    08/31/2020, 1:57 PM
    Hey, I heard Intellij and apps based on it are soon going to move to JCEF (in 2020.2 release), is it true? I wanna ask because I was planning to learn JavaFx but it seems it might be a bad idea because I didn't saw any apps built on it (as ones which I use) and heard its about to dead in 2020. Should I learn about CEF instead?
    j
    2 replies · 2 participants
  • b

    Big Chungus

    08/31/2020, 2:35 PM
    Guys, I'm out of my depth here, maybe someone will be able to help here. I have a MPP multi-module project, that worked fine with 1.4.0-M3, but after I update to 1.4.0, all modules that have dependencies on other modules do not build with attached error...
    scratch.txt
    r
    i
    21 replies · 3 participants
  • c

    colintheshots

    08/31/2020, 3:31 PM
    I'm using Gradle wrapper 6.6, but I keep getting this error when compiling my Gradle Kotlin DSL buildSrc code. Why is it using a much older Gradle version for buildSrc? Or is the message bogus?
    * What went wrong:
    An exception occurred applying plugin request [id: 'org.jetbrains.kotlin.jvm', version: '1.4.0']
    > Failed to apply plugin [id 'org.jetbrains.kotlin.jvm']
       > The current Gradle version 5.2.1 is not compatible with the Kotlin Gradle plugin. Please use Gradle 5.3 or newer, or the previous version of the Kotlin plugin.
    b
    j
    27 replies · 3 participants
  • a

    Alex Anisimov

    08/31/2020, 6:09 PM
    https://twitter.com/kotlin/status/1300493552997355520
    n
    c
    +2
    7 replies · 5 participants
  • m

    M. Taufiq Hidayat

    08/31/2020, 11:28 PM
    It's Kotlin native only?? And run from the same project in Android studio?
    r
    1 reply · 2 participants
  • v

    vinny2020

    09/01/2020, 4:07 AM
    anyway to add some validation to the primary constructor of a data class? For example I don’t ever want the first parameter to be a negative number
    r
    t
    +2
    8 replies · 5 participants
  • a

    addamsson

    09/01/2020, 9:04 AM
    Hi there! Is there a way to filter for generic type parameters as well? For example here:
    entity::class.members.filterIsInstance<KProperty<Entity>>().forEach { p ->
        println("prop: $p")
    }
    it doesn't filter for
    Entity
    . I've read somewhere that there is support for this, I just can't find it
    d
    3 replies · 2 participants
  • d

    DALDEI

    09/01/2020, 11:03 AM
    Bug Or 'Feature' witn Kotlin 1.4 + Jackson 2.11 Updateing code previously compiling with Kotlin 1.3.61 , Jackson 2.9.8 to Kotlin 1.4 + Jackson 2.11 This Java function
    public <T extends JsonNode> T set(String fieldName,
                                      JsonNode value)
    Is throwing off Kotlins type inference for expressions like val node : ObjectNode = /// assign val value : JsonNode = // assign node.set("field" , value ) and node["field"] = value The error is cannot determine type for type parameter T I can get the former to work with node.set<JsonNode>( "field", value ) I have not gotten the later to work at all -- I dont know how to explicty type the fun type parameters to an operator overload These lame attempts didnt work -- but I didnt expect them node<JsonNode>{"field" ] = value node([<JsonNode>) "field" ] = value
    m
    a
    2 replies · 3 participants
  • t

    TwoClocks

    09/02/2020, 5:26 AM
    how should one deal w/ removing something from a list while your are in the middle of
    forEach{}
    over it? Does it explode, or what?
    💥 1
    b
    e
    +2
    11 replies · 5 participants
  • t

    thana

    09/02/2020, 8:36 AM
    is there a compiler-flag to turn the generated warning about a non-exhaustive
    when
    into an error? (i know i can turn the
    when
    statements themselves into expressions, but sometimes this gets forgotten)
    a
    e
    +1
    5 replies · 4 participants
  • p

    Philipp Mayer

    09/02/2020, 8:53 AM
    As you all know, functional interfaces were added in Kotlin 1.4. Tbh, for me, a backend guy, this feature was something that I didn't hear before. What are some real world usecases for it? Thanks!
    k
    t
    +3
    19 replies · 6 participants
  • s

    Shabinder Singh

    09/02/2020, 3:58 PM
    Can Someone please help me with this question...? https://www.hackerrank.com/challenges/between-two-sets/forum My answer fails two test cases , becuz pf timeout...😥 Answer: https://justpaste.it/50bns Thanks in advance....
    t
    x
    7 replies · 3 participants
  • j

    janvladimirmostert

    09/02/2020, 8:00 PM
    is there a way to make use of an infix modifier in a "postfix" kinda way, in othe words being allowed to exclude the trailing param? This is what i'm trying to do, but i'm forced to trail the DSL with a garbage value, in this case Unit
    infix fun postgresql.DESC(value: Unit): postgresql {
    			return this
    		}
    
    	}
    
    
    	fun main() {
    
    		postgresql {
    			SELECT (
    				ListingTable::section, ListingTable::id,
    				ListingImageTable::name, ListingImageTable::listingId
    			) FROM (
    				ListingTable::class
    			) LEFT JOIN (
    				ListingImageTable::class
    			) ON (
    				ListingTable::id == ListingImageTable::id
    			) WHERE (
    				true
    			) ORDER BY(ListingTable::modified) DESC Unit
    
    
    		}
    n
    b
    18 replies · 3 participants
  • e

    eygraber

    09/02/2020, 8:45 PM
    Is there any way to get a method reference to a constructor when accessing it through a FQN? i.e.
    ::kotlinx.serialization.json.JsonObject
    throws a compiler error
    n
    e
    10 replies · 3 participants
  • t

    TwoClocks

    09/02/2020, 10:29 PM
    null safety : if I
    require(foo != null)
    then after that the compiles knows foo can't be null. But if I
    assertTrue( foo != null)
    I have to use
    foo?.
    or
    foo!!.
    there after. why is that? Both
    require
    and
    assertTrue
    throw exceptions... why can't the compiler figure it for one and not the other? Or is it just a hard-coded list of functions someplace?
    r
    n
    +1
    10 replies · 4 participants
  • g

    groostav

    09/03/2020, 2:17 AM
    Regarding immutable data classes in kotlin, I remember there was some discussion about a more elegant way of ~mutating member values. I think Arrow.kt adds some functionality here. Did kotlin 1.4 introduce anything new here?
    z
    n
    5 replies · 3 participants
  • a

    Artem Kopan

    09/03/2020, 11:53 AM
    Does anyone know how to instal Kotlin Multiplatform Mobile Plugin on Android Studio 4.2 canary9 ?
    j
    a
    4 replies · 3 participants
  • n

    NurBahnhof

    09/03/2020, 3:14 PM
    Can I annotate a method from the parent class in Kotlin without explicitly writing a wrapper?
    n
    1 reply · 2 participants
  • u

    user

    09/03/2020, 3:30 PM
    message has been deleted
    n
    t
    2 replies · 2 participants
  • n

    NurBahnhof

    09/03/2020, 3:57 PM
    Do kotlin methods inherit annotation? From my test it seems yes. How do I disable it?
    n
    c
    13 replies · 3 participants
  • s

    stephanmg

    09/03/2020, 4:49 PM
    hi guys, is there something similiar like pypi for Kotlin?
    t
    m
    +1
    28 replies · 4 participants
  • w

    Wesley Acheson

    09/03/2020, 4:51 PM
    Anyone know where I should ask about maven? I'm not able to see dokka-maven-plugin?
    e
    a
    5 replies · 3 participants
  • a

    AlexJuca

    09/03/2020, 5:41 PM
    Hi guys! Need some help to see if this is possible.
    class CustomKlass(val status: Int = 0,
                               val code: String? = null,
                               val message: String? = null,
                               val type: String? = null): ErrorResponse {
    
       
    }
    Is it possible to generate a function with the same parameters as this class (possibly at compile time) ?
    s
    n
    7 replies · 3 participants
  • m

    MrNiamh

    09/03/2020, 6:05 PM
    is there a way to get just the time, no date?
    r
    n
    +2
    7 replies · 5 participants
  • u

    user

    09/04/2020, 10:43 AM
    Dokka Alpha for Kotlin 1.4 We’ve released Dokka (Alpha) on Kotlin 1.4! This release aligns Dokka with the latest stable version of the Kotlin compiler. It focuses on reducing the amount of configuration required to use Dokka in the most common cases – including Kotlin multiplatform projects – because spending less time writing Dokka configuration means more time to write […]
    🙌 1
    ➕ 3
    🎉 9
    :kotlin: 3
    d
    1 reply · 1 participant
  • s

    stephanmg

    09/04/2020, 12:57 PM
    Failed to apply plugin [id 'org.jetbrains.kotlin.jvm']
    223   > The current Gradle version 5.1.1 is not compatible with the Kotlin Gradle plugin. Please use Gradle 5.3 or newer, or the previous version of the Kotlin plugin.
    k
    j
    +1
    10 replies · 4 participants
  • m

    muliyul

    09/04/2020, 1:21 PM
    Hey guys what do you think about #collaborations?
    ➖ 1
    m
    1 reply · 2 participants
  • g

    Gus

    09/04/2020, 1:29 PM
    Hi. I want to refer to a method in a companion object and something like
    TheClass.Companion::method
    works, but is there an alternative that doesn't involve using
    .Companion
    ? Something like
    TheClass::method
    would've been great but it only works with instance methods. I'm using Kotlin 1.4 in case that's relevant.
    g
    s
    4 replies · 3 participants
  • p

    pp.amorim

    09/04/2020, 3:00 PM
    any idea?
    a
    2 replies · 2 participants
  • p

    pp.amorim

    09/04/2020, 3:01 PM
    I don’t understand why Short + Short is giving an Int
    d
    o
    +4
    9 replies · 7 participants
Powered by Linen
Title
p

pp.amorim

09/04/2020, 3:01 PM
I don’t understand why Short + Short is giving an Int
d

David Silva

09/04/2020, 3:14 PM
I don't know why but it might be because the numeric operator APIs in Kotlin sort-of follows the numeric promotion rules that JSL defines? 🤷‍♂️ https://docs.oracle.com/javase/specs/jls/se11/html/jls-5.html#jls-5.6.2 Maybe someone else can shed some light on the topic.
o

outadoc

09/04/2020, 3:21 PM
Short (at least on the JVM) can go up to 32,767. If you add two values that can go up to 32,767, you get a maximum value of 65,534, which can’t be stored in a Short
t

Tobias Berger

09/04/2020, 3:24 PM
Binary numeric operations that don't use double, float or long will always be converted to int for the calculation. I'm no expert on the deep inner workings of this, but I guess this is due to how the machine code works and the binary commands probably need an int-sized number. Now, if the calculation happens as an int, it makes sense to also return that and not artificially limit the result to something smaller. If you need a short as your result, you will have to manually convert it back.
@outadoc I don't see that as an argument. You could also add two ints and get a value that doesn't fit, but that operation doesn't return a long.
o

outadoc

09/04/2020, 3:27 PM
True, your explanation makes more sense 🙂
j

Jonathan Mew

09/04/2020, 3:53 PM
The JVM operand stack is specified as having 32-bit units, where a long/double takes up two units and everything else takes up 1. Not sure why that is offhand, but I guess it follows @Tobias Berger’s argument from there. Old JVM spec but pretty sure it still applies! https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.html#jvms-2.6.2
e

ephemient

09/04/2020, 11:53 PM
yes, there are no boolean/byte/short/char types in JVM's frames' local variables and operand stacks, they're all represented by int
like Java and C, Kotlin's arithmetic promotes narrower types up to int
a

Animesh Sahu

09/05/2020, 4:50 AM
Because there is no JVM Bytecode that does addition of Short. And Short by default uses 4 bytes similar to Int unless they are in a ShortArray.
View count: 2