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

    Hullaballoonatic

    05/04/2019, 4:34 AM
    And as an aside... It's so hard to make linear algebra related code elegant, succinct, and optimal in runtime. oh, and i'm still really hoping for pow
    **
    and root
    \\
    operators (is backslash ever used outside of character and strings?).
    k
    • 2
    • 4
  • j

    jishindev

    05/04/2019, 10:01 AM
    https://www.zdnet.com/article/a-hacker-is-wiping-git-repositories-and-asking-for-a-ransom/
    r
    j
    • 3
    • 2
  • j

    jimn

    05/04/2019, 1:47 PM
    why can't Intellij see native kotlin assert ?
    d
    l
    • 3
    • 15
  • d

    davidasync

    05/04/2019, 6:07 PM
    Assume I have project that compile the project into java 7 binary code, If I use kotlin library, can i use library that has minimal java version, java 8, for example resilience4j, ahc, with kotlin?
    l
    • 2
    • 1
  • d

    Dico

    05/04/2019, 11:46 PM
    Upvotes on https://github.com/FasterXML/jackson-module-kotlin/issues/225 would be appreciated!
    l
    • 2
    • 6
  • h

    Hullaballoonatic

    05/05/2019, 1:11 AM
    What's stopping JB from adding functionality like this:
    3..0 // 3, 2, 1, 0
    ?
    i
    g
    l
    • 4
    • 15
  • h

    Hullaballoonatic

    05/05/2019, 1:43 AM
    more than anything, i want JB to expand on the
    rangeTo ..
    operator to add descending and unbounded functionality, e.g.
    list[3..]
    ➕ 2
    g
    g
    • 3
    • 7
  • m

    Mike

    05/05/2019, 1:08 PM
    I suspect most people feel it should be inclusive. I know I think that way. But obviously it's comfort and learning. Just like Java's substring takes time to learn. Generally people think it's inclusive of end index when it isn't.
    d
    k
    g
    • 4
    • 18
  • e

    elect

    05/05/2019, 7:33 PM
    any way to transform this into a
    tailrec
    ? And get rid of the
    !!
    ?
    while (window.flags has Wf.ChildWindow && window.parentWindow != null)
        window = window.parentWindow!!
    s
    • 2
    • 16
  • e

    elect

    05/06/2019, 9:40 AM
    Comparing `Float`s, I'd like to know if
    ==
    (and also
    Float.compareTo
    ) will call
    java.lang.Float.compare()
    under the hood
    k
    d
    l
    • 4
    • 16
  • f

    Felix Robles

    05/06/2019, 11:29 AM
    I haven't, first time I read about it
    s
    • 2
    • 1
  • r

    robstoll

    05/06/2019, 12:43 PM
    Is there a way to define a function for all Array types (IntArray, LongArray, etc.)
    k
    • 2
    • 1
  • b

    Bernhard

    05/06/2019, 12:57 PM
    is set.toList() deterministic?
    l
    a
    +6
    • 9
    • 44
  • i

    iex

    05/06/2019, 3:39 PM
    Hi. Isn't there anything out of the box to convert an
    Int
    into a
    ByteArray
    ?
    d
    • 2
    • 3
  • c

    Chi

    05/06/2019, 7:09 PM
    how can we write this java code in Kotlin?
    -.java
    d
    l
    r
    • 4
    • 4
  • c

    Chi

    05/06/2019, 7:10 PM
    end up writing it with
    while
    loop
    s
    • 2
    • 3
  • r

    Rohan Maity

    05/06/2019, 9:08 PM
    @elizarov could I DM you ?
    e
    • 2
    • 1
  • c

    crummy

    05/06/2019, 11:11 PM
    I'm getting a platform declaration clash:
    val Map<UInt, UInt>.hex: String
        get() = this.map { "${it.key.hex}=${it.value.hex}" }.toString()
    
    @get:JvmName("mapIntByteHex")
    val Map<UInt, UByte>.hex: String
        get() = this.map { "${it.key.hex}=${it.value.hex}" }.toString()
    I added the
    @JvmName
    annotation to fix the error in the IDE. However, when I try to build I still get an error:
    Error:(1, 1) Kotlin: Platform declaration clash: The following declarations have the same JVM signature (hex$annotations(Ljava/util/Map;)V):
        val Map<UInt, UByte>.hex: String...
        val Map<UInt, UInt>.hex: String...
    Is there a way around this without changing the property names?
    k
    i
    • 3
    • 4
  • l

    LeoColman

    05/07/2019, 3:01 AM
    Java-like for statements are not supported, right? I was following Uncle Bob's prime factor kata, and something similar to this was made in java:
    for(int divisor = 2; n > 1; divisor++) {
        for(; n % divisor == 0; n /= divisor) {
            ...
        }
    }
    s
    r
    a
    • 4
    • 13
  • j

    Josué

    05/07/2019, 11:25 AM
    Is Github down?
    t
    • 2
    • 3
  • m

    Marko Mitic

    05/07/2019, 11:34 AM
    Any plans for making any of these expressions constant?
    companion object {
       const val TAG1 = this.javaClass.simpleName
       const val TAG2 = MainActivity::class.simpleName!!
    }
    Obfuscation mangles class names so having them assigned to constants before obfuscation pass would be greatly useful. (Or is there a way to this that I'm missing)
    n
    k
    • 3
    • 10
  • w

    william

    05/07/2019, 3:57 PM
    Can I do anything in this snippet to prevent the need from using a generic and passing in the
    Class
    as well?
    abstract class BaseViewModelFragment<T : ViewModel>(private val type: Class<T>) : BaseInjectedFragment() {
        @Inject
        lateinit var viewModelFactory: ViewModelProvider.Factory
        private lateinit var viewModel: T
    
        override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
            super.onViewCreated(view, savedInstanceState)
            viewModel = ViewModelProviders.of(this, viewModelFactory).get(type)
        }
    }
    🇳🇴 1
    w
    s
    • 3
    • 19
  • k

    kd

    05/07/2019, 7:07 PM
    Is there an idiomatic way to diff between two lists, based on some value? I tried to use the minus opertaor and it gave the first one as the diff too. Do not want that
    Untitled.kt
    j
    • 2
    • 4
  • y

    Yossi Saiada

    05/07/2019, 8:24 PM
    enum class EnumA {
        A, B;
        val group = EnumB.values().find { this == it.enumA }
    }
    
    enum class EnumB(val enumA: EnumA) {
        A1(EnumA.A),
        B1(EnumA.B),
    }
    
    EnumB.values().map { it.enumA } // => [null, null]
    EnumA.A.group  // == null
    EnumB.values().find { EnumA.A == it.enumA }  // == null
    Why does EnumB.enumA, for every EnumB value, equals
    null
    ? (I know it's happening because of the circular dependency (caused by the group property), but I'm not sure it should be like that) Edit: I'm a bit confused. I had thought the reason is the circular dependency, but this code:
    enum class EnumA(val enumB: EnumB) { A(EnumB.B) }
    enum class EnumB(val enumA: EnumA) { B(EnumA.A) }
    EnumB.values().map { it.enumA }
    actually works as expected and return
    [A]
    . 🤨
    a
    • 2
    • 1
  • a

    amanda.hinchman-dominguez

    05/08/2019, 12:23 AM
    I wanna say no but why allow this in a constructor parameter?
    n
    i
    p
    • 4
    • 12
  • a

    amanda.hinchman-dominguez

    05/08/2019, 1:05 AM
    Ah, I think I ran into a limit - you can sure pass a vararg of functions, but I don't know about a vararg of any parameters within the function
    a
    • 2
    • 1
  • p

    Pere Casafont

    05/08/2019, 6:10 AM
    Is there a natural way to have a multiple sentence block as the right side of an elvis operator? So far I can type only a single expression and if I add curly braces it is detected as a lambda. I have implemented
    Any?.orElse(block: () -> Nothing)
    which works for the purpose like a charm but then I wonder why there isn't anything like that in the language itself or the stdlib, maybe I am missing something?
    p
    • 2
    • 4
  • n

    nickk

    05/08/2019, 8:14 AM
    So, Kotlin has its own type for Exceptions. Wouldn’t it make sense if
    Throwable
    was an alias for
    java.lang.Exception
    on the JVM? Anyway, I have run into this problem:
    kotlin.NotImplementedError cannot be cast to java.lang.Exception
    and I am thinking what is the best way to avoid it. It happens somewhere in my java dependencies (RxJava perhaps). Your thoughts, please?
    l
    a
    +3
    • 6
    • 16
  • n

    Nikita Yatskivskiy

    05/08/2019, 11:30 AM
    Hello there! I am concerned about unsigned types - I know that they are experimental yet, but I'd like to use them in production code. Should I worry about that they can be removed from language?
    l
    k
    • 3
    • 2
  • f

    frellan

    05/08/2019, 11:34 AM
    A general question, what Java/JVM version should you run on if you are running a server in purely kotlin? I am currently on
    kotlinOptions.jvmTarget = "1.8"
    and that feels a bit ancient, I have not really followed what has happened to to jvm since the Stream API basically. What is a sensible version to run the latest kotlin versions on now? Are there any performance improvements for kotlin?
    k
    s
    • 3
    • 7
Powered by Linen
Title
f

frellan

05/08/2019, 11:34 AM
A general question, what Java/JVM version should you run on if you are running a server in purely kotlin? I am currently on
kotlinOptions.jvmTarget = "1.8"
and that feels a bit ancient, I have not really followed what has happened to to jvm since the Stream API basically. What is a sensible version to run the latest kotlin versions on now? Are there any performance improvements for kotlin?
k

karelpeeters

05/08/2019, 11:35 AM
Note that the steam api is totally unrelated to the JVM, that's purely a java thing.
f

frellan

05/08/2019, 11:36 AM
Ah okay, I know they are unrelated but I thought the introduction of such a big shift required some new JVM instructions
k

karelpeeters

05/08/2019, 11:36 AM
AFAIK Kotlin doesn't target anything above 1.8 yet, but you can and probably should still run on the newest JVM possible for performance and bug fixes.
f

frellan

05/08/2019, 11:36 AM
Java 8 was maybe a much bigger release on the Java side then on the JVM side then maybe
s

Stephan Schroeder

05/08/2019, 11:37 AM
if you use Kotlin version >=1.3.30 you can set the jvmTarget to newer versions 9-12. There are no performance improvements yet, but there will be, so that’s where i’d start. https://blog.jetbrains.com/kotlin/2019/04/kotlin-1-3-30-released/#more-6991
👍 3
f

frellan

05/08/2019, 11:38 AM
Alright, great 🙂 upgrading the JVM always felt like packing up and moving to a new universe, have a hard time getting used to the JVMs new release schedule
k

karelpeeters

05/08/2019, 11:38 AM
There are special JVM instructions, but they're not necessary. There's an issue about the Kotlin compiler actually using them, can't find it easily on mobile though.
View count: 4