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
getting-started
  • b

    Bart

    08/28/2021, 7:58 PM
    Hello all! Im struggling with setting a ktorm in my project. I try to add dependencies in below way:
    Implementation("org.ktorm:ktorm-core:${ktorm.version}")
    Unfortunately its ending with error
    Unresolved reference: ktorm
    Any idea why? Following ktorm documentation it should work in this way :(
    t
    r
    • 3
    • 3
  • h

    Hamza GATTAL

    08/28/2021, 9:35 PM
    Hi @Alina Dolgikh [JB] Bring tweets back into slack
    y
    a
    d
    • 4
    • 3
  • e

    Erdem Tuna

    08/30/2021, 9:35 AM
    Hello, does anybody have an example of Gradle script with Kotlin DSL (
    build.gradle.kts
    ) where I can input custom arguments when running? Actually, as I understand, I need to define new task that can take command-line input and invoke the main.
    j
    p
    c
    • 4
    • 10
  • a

    acoconut

    08/30/2021, 12:47 PM
    hey! do you all use some kind of code style formatter for your kotlin projects? We’re looking into it and have found the spotless plugin but i really don’t like the way ktfmt formats data classes. I think:
    data class Book (
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     val id: Long? = null
    )
    is way easier to read than:
    data class Book (
     @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long? = null
    )
    What do you all use if anything?
    r
    v
    +2
    • 5
    • 9
  • g

    Gopal S Akshintala

    08/31/2021, 5:43 AM
    Can someone help me understand what does this exception mean. I am trying to use
    CollectionsKt
    method directly in java and run this in a unit test. However this static import is causing this exception
    import static kotlin.collections.CollectionsKt.chunked;
    However, if I use
    CollectionsKt.chunked(…)
    without the static import, I don’t get this exception:
    java.lang.IllegalAccessError: failed to access class kotlin.collections.CollectionsKt___CollectionsKt from class billing.batch.invoice.services.tax.TaxIntegrator (kotlin.collections.CollectionsKt___CollectionsKt and billing.batch.invoice.services.tax.TaxIntegrator are in unnamed module of loader org.powermock2.core.classloader.javassist.JavassistMockClassLoader @5443d039)
    j
    • 2
    • 9
  • m

    maarten ha

    08/31/2021, 3:15 PM
    Hey everyone, Currently I'm trying to start a jetpack compose project with android but I want the gradle to be in kotlin instead of groovy because I'm more comfortable with it. I tried to follow a guide but sadly after it gives me error on in the app build.gradle.kts. Error in thread.
    l
    • 2
    • 6
  • s

    Saharath Kleips

    09/01/2021, 5:59 PM
    I have a question about a behavior around `value class`es. From my understanding they’re (in most cases) a zero-overhead way to make a “type-safe primitive”. But what happens in the case of collections and moving between the primitive and the value class?
    value class Box(val str: String)
    val letters: List<String> = listOf("A","B","C",...)
    
    val boxes: List<Box> = letters.map(::Box)
    val backToLetters: List<String> = boxes.map(Box::str)
    Are there any costs associated with moving between a
    List<String>
    and
    List<Box>
    and vice versa?
    e
    z
    +2
    • 5
    • 7
  • m

    Mahir Chowdhury

    09/01/2021, 8:19 PM
    Hello guys! Thanks for the invite. I have two questions: 1. I'm working with compose for desktop and I seem to not be able to import Glide into my project. Is that intentional or is it something which will be fixed later? 2. Also, I have been trying to make a LazyRow scrollable without the scroll bar. I wanted the row to be draggable. I was able to simulate this feature with the code below but I was wondering if there was a better way.
    z
    k
    e
    • 4
    • 6
  • m

    Mahir Chowdhury

    09/01/2021, 8:19 PM
    LazyRow(
        state = listState,
        modifier = Modifier.fillMaxWidth().padding(50.dp, 0.dp)
            .pointerInput(Unit) {
                detectHorizontalDragGestures { _, dragAmount ->
                    coroutineScope.launch {
                        if (dragAmount < 0) {//scroll right
                            listState.animateScrollToItem( listState.firstVisibleItemIndex+2)
                        } else if (dragAmount > 0) {//scroll left
                            listState.animateScrollToItem(listState.firstVisibleItemIndex -1)
                        }
                    }
                }
            },
        horizontalArrangement = Arrangement.spacedBy(10.dp)
    )
    This is what I have in the parameters for LazyRow
    r
    • 2
    • 2
  • j

    James Whitehead

    09/02/2021, 1:00 AM
    Hi all, I have a question RE Gradle + Kotlin, x-posting here as I got no response in the gradle channel :(
    🇳🇴 2
    h
    e
    j
    • 4
    • 10
  • j

    Jérémy CROS

    09/02/2021, 9:45 AM
    Hi guys 🙂 What would be the most idiomatic way to add 2 elements to a list, one at the beginning and one at the end? So far I have
    listOf(element0) + listOfElements + elementLast
    But I’m not sure if there are more efficient / maybe clearer options available ?
    j
    k
    m
    • 4
    • 5
  • e

    Erik

    09/02/2021, 3:27 PM
    When naming an extension on some type A that returns a type B, what are the conventional names for such functions? For example, there are •
    fun <T> Array<out T>.asList(): List<T>
    •
    fun <T> Array<out T>.toList(): List<T>
    By signature, they are identical. So the behaviour must define the naming difference. Likewise, there exists a
    fun <T> Array<out T>.asIterable(): Iterable<T>
    but not
    toIterable
    . Then there are all kinds of variants that use names like
    mapTo
    . When do you use
    as
    ,
    to
    ,
    mapTo
    or something else?
    d
    • 2
    • 4
  • e

    Erik

    09/02/2021, 3:31 PM
    And more general than my question above: is there a comprehensive list of naming conventions used in Kotlin Some examples: the stdlib is full of functions that have an
    OrNull
    variant. Or in the coroutines lib, it's conventional to either write a
    suspend fun foo()
    or write a non-suspending extension
    fun CoroutineScope.foo()
    , but not
    suspend fun CoroutineScope.foo()
    . And likewise,
    suspend fun foo(): Flow<Bar>
    usually doesn't make sense, but
    fun foo(): Flow<Bar>
    is more conventional. It's probably a good idea to use the same naming conventions in your own Kotlin APIs.
    c
    j
    • 3
    • 4
  • g

    GUIGAL Allan

    09/03/2021, 4:49 PM
    Is it possible to have a reified T for this operator fun ? Or to know the T class at runtime ?
    operator fun getValue(thisRef: Any?, property: KProperty<T>): T {
    e
    t
    • 3
    • 11
  • a

    Ayfri

    09/03/2021, 7:33 PM
    Hi, do you have any good idea on how to generate secure random IDs ? For a project I need to have IDs for objects, the first digits will be the actual timestamp but then I need at least 5 numbers that should never be the same even in the same millisecond I don't want a super-secure thing, it's just for a personal project with my friends but at least an interesting and important tech to use in development like uuids (so it could be useful for me for future jobs I guess).
    d
    h
    +2
    • 5
    • 6
  • a

    Alexander Suraphel

    09/04/2021, 3:11 PM
    can someone tell me why this is allowed in Kotlin but not in Java?
    var animals: List<Animal> = ArrayList<Dog>()
    where
    Dog
    ->
    Animal
    The following won’t compile in Java:
    List<Animal> animals = new ArrayList<Dog>();
    y
    m
    • 3
    • 4
  • s

    Stylianos Gakis

    09/05/2021, 8:24 AM
    I am working with collections, doing the classic
    map
    filter
    associate
    and whatnot, but I wanted to debug it. In Java streams we can use the “trace current stream chain” while debugging, but it seems to be greyed off in Kotlin. If I use the
    asSequence
    I get this functionality, but is this the only way? Sometimes a sequence doesn’t make sense to use, and using it just to enable this debugging functionality feels wrong, is this my only option?
    e
    j
    • 3
    • 12
  • m

    Muhammet Emin Gündoğar

    09/05/2021, 10:39 AM
    i have 2 questions what is difference between .toString and as String second question is: can we do both upcasting and downcasting with as keyword?
    r
    • 2
    • 14
  • i

    igor.wojda

    09/06/2021, 6:16 AM
    Hey What are you thought on using
    Collection
    type? Fine / Not Fine? and Why?
    val modifiers: Collection<Modifier> = emptyList()
    t
    s
    • 3
    • 2
  • n

    nilTheDev

    09/06/2021, 2:02 PM
    I thought only data classes have 
    equals/hashcode
     method implemented by default. But it turns out,
    class SomeClass(val a: String)
    
    fun main(){
        val someClass1 = SomeClass("abcd")
        val someClass2 = SomeClass("abcd")
    
        println(someClass1 == someClass2) // this code is also valid
    }
    ==
    is also supported in regular classes. How does it behave? Is
    ==
    is same as
    ===
    in case of non-data classes?
    p
    c
    • 3
    • 5
  • t

    The Monster

    09/06/2021, 4:00 PM
    What is the point of List.component1 -> 5 functions?
    j
    • 2
    • 6
  • z

    Zyle Moore

    09/06/2021, 8:29 PM
    Is there somewhere that details the differences between a top-level function variable, and a top-level function, and what considerations there are in choosing one over the other?
    m
    t
    c
    • 4
    • 4
  • t

    The Monster

    09/06/2021, 11:14 PM
    inline fun test(crossinline callback: () -> Unit){
        callback()
    }
    The doc says: some
    inline
    functions may call the lambdas passed to them as parameters not directly from the function body, but from another execution context, such as a local object or a nested function.
    which I understood as: an
    inline
    function is not allowed to call the
    crossinline
    parameter directly in its scope, ...
    But why does the code snippet works and I was able to call
    callback()
    directly? Does the doc meant to say that you can call the
    crossinline
    argument directly and within another local scope as well?
    j
    • 2
    • 11
  • c

    Chachako

    09/07/2021, 1:17 AM
    Hello everyone, do someone know how to merge the repeated content in the path string? E.g.
    new.foo.bar.foo.bar.baz
    merged to
    new.foo.bar.baz
    foo.bar.foo.bar.qux
    merged to
    foo.bar.qux
    but
    foo.bar.break.foo.bar
    does not merge 🤯
    t
    m
    s
    • 4
    • 8
  • s

    Simon Lin

    09/07/2021, 5:56 AM
    Can I apply multiple Comparator for a list? for example: I have a
    HashMarkOrderComparator
    to put
    #
    in the last and I also need
    String.CASE_INSENSITIVE_ORDER
    Comparator. How can I combine this two
    Comparator
    ?
    i
    • 2
    • 2
  • c

    Chachako

    09/07/2021, 9:11 AM
    Is there a function in List that can achieve the uniform behavior of String
    removeSuffix
    or
    removePrefix
    ?
    e
    j
    k
    • 4
    • 8
  • m

    Muhammet Emin Gündoğar

    09/07/2021, 10:11 AM
    why we use sealed classes i read documentation and i use it in deciding situations in android like error,success but i want to ask why we use sealed classes instead of normal class or enums what is the advantages of sealed class over them?
    j
    • 2
    • 3
  • w

    William Reed

    09/07/2021, 4:00 PM
    could someone help point me in the right direction to obtain the primary constructor arguments (to get their names and types) in an annotation processor? i am currently reading about kotlin metadata to see if that can be helpful
    s
    • 2
    • 1
  • e

    elect

    09/07/2021, 4:04 PM
    I have an inline function calling on its turn a super inline function, but Idea warnings me
    Accessing super members from public-API inline function is deprecated
    why?
    a
    • 2
    • 16
  • m

    Muhammet Emin Gündoğar

    09/08/2021, 3:19 PM
    hi guys i was reading a project from github and i saw @Suppress("UNCHECKED_CAST") and i wondered why is it used and i searched but nobody explained what is checked cast.Can you explain how can check casting and when we use this suppress?
    p
    • 2
    • 1
Powered by Linen
Title
m

Muhammet Emin Gündoğar

09/08/2021, 3:19 PM
hi guys i was reading a project from github and i saw @Suppress("UNCHECKED_CAST") and i wondered why is it used and i searched but nobody explained what is checked cast.Can you explain how can check casting and when we use this suppress?
p

Paul Griffith

09/08/2021, 3:24 PM
https://kotlinlang.org/docs/typecasts.html#unchecked-casts
View count: 10