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

    Ifvwm

    05/21/2020, 5:48 AM
    aob = ByteArray(1024)
    e
    • 2
    • 1
  • m

    Mananpoddarm

    05/22/2020, 8:05 AM
    Hi everyone! I am new to kotlin and I am searching a way to use kotlin multiplatform for sharing codebase specifically between android and web platforms. could anyone help here by giving me any suggestion or resources that may be helpful.
    a
    • 2
    • 1
  • m

    Mark

    05/23/2020, 1:34 AM
    What is the best pattern for where to implement equals/hashCode/toString in a class hierarchy where there is one interface with many implementing classes? I would like to define this in one place (because in this case the implementations would be the same for all classes). Kotlin doesn’t allow to define them on the interface. The obvious solution is have a single base class that all other classes extend from, but then that base class cannot be private (because other implementing classes are public) and what if a class is already extending a class.
    s
    • 2
    • 4
  • j

    Joshua

    05/23/2020, 11:57 AM
    Hey guys, how do I get the view of a fragment from my activity?
    r
    • 2
    • 1
  • j

    JP

    05/23/2020, 6:30 PM
    A question regarding
    any
    and `all`: do they short-circuit, or do they evaluate the predicates for the whole items?
    e
    • 2
    • 2
  • b

    bitnot

    05/23/2020, 7:49 PM
    Hey there! Could someone point me to some docs explaining why
    val (_) = Unpackable("Two")
    does not call
    component1
    ?
    m
    e
    • 3
    • 6
  • m

    Mark

    05/24/2020, 3:37 AM
    In a companion object, is it acceptable practice for
    operator fun invoke(...): MyClass?
    to return a nullable value, or is that confusing to the caller since it looks like a constructor call?
    j
    k
    m
    • 4
    • 4
  • m

    Mark

    05/24/2020, 6:28 AM
    Is there a standard library function to convert a sequence of sequences like this:
    {{A}, {B, C}, {D, E}}
    to
    {{A, B, D}, {A, C, D}, {A, B, E}, {A, C, E}}
    ?
    k
    • 2
    • 2
  • a

    Ali

    05/27/2020, 6:14 PM
    I haven't used Intellij for a long time so this is a new configuration. I am setting up my Java and Gradle for the first time on this system, for this Ktor quickstart project.
    s
    k
    m
    • 4
    • 12
  • j

    JP

    05/28/2020, 6:50 AM
    What is the
    hashCode()
    and
    toString()
    implementation for the cases where I don’t define a class as data class? For example when I examined with a class like this:
    class ListNode(var elem: Int) {
        var next: ListNode? = null
    }
    
    fun main() {
        val node = ListNode(123)
        println(node.hashCode())  // 895328852
        println(node.toString())  // ListNode@355da254
    
        node.elem = 456
        println(node.hashCode())  // 895328852
        println(node.toString())  // ListNode@355da254
    }
    whereas when I examined when changing to data class:
    data class ListNode(var elem: Int) {
        var next: ListNode? = null
    }
    
    fun main() {
        val node = ListNode(123)
        println(node.hashCode())  // 123
        println(node.toString())  // ListNode(elem=123)
    
        node.elem = 456
        println(node.hashCode())  // 456
        println(node.toString())  // ListNode(elem=456)
    }
    From this my assumption is that the
    hashCode()
    and
    toString()
    depends on the memory address when the class is not a data class, whereas in case of data class, it will not depend on the memory address but the properties which are defined in the primary constructor (which makes sense, since that would be what data classes are for and how they should behave). Is my assumption correct? And where can I see these default implementations for
    hashCode()
    , both for class and data class? I wasn’t able to find them.
    a
    m
    • 3
    • 7
  • s

    Slackbot

    05/29/2020, 10:25 AM
    This message was deleted.
    m
    g
    t
    • 4
    • 5
  • c

    ClaudiuB

    05/29/2020, 7:19 PM
    I guess a "getting started" question although just shipped production full kotlin 😆 Will this be only evaluated once because
    val
    -ness, a sort of
    lazy by
    ? Confused of the heuristics here. Should I make it
    var
    if I plan on it changing?
    adapter
    doesn't change, the
    onActionPerformed
    can
    val onActionPerformed: ((String, Any) -> Unit)?
            get() {
                return adapter?.onActionPerformed
            }
    a
    c
    • 3
    • 31
  • m

    Mark

    06/01/2020, 2:41 AM
    Are these two equivalent (just checking for any gotchas)?
    if (text.length < 40) {
        // left pad with zeros
        text = String(CharArray(40 - text.length)).replace('\u0000', '0') + text
    }
    text = text.padStart(40, '0')
    m
    • 2
    • 6
  • o

    oday

    06/01/2020, 9:59 AM
    not sure how to make the list-to-be-added iterable so that it can be fed straight into addAll
    a
    m
    • 3
    • 2
  • r

    Rishav Sharan

    06/01/2020, 6:49 PM
    First time on Kotlin and intellij. Can anyone tell me why some of my function names in intellij have a strikethrough them? Here the
    init
    name has a strikethrough
    s
    • 2
    • 3
  • o

    oday

    06/03/2020, 12:31 PM
    will this replace the item found in
    it.items
    with a new object whose
    toggled
    variable is now changed?
    it.items.map { item ->
        item.copy(toggled = createSearchParams?.condition?.contains(item.itemValue)!!)
    }
    :yes: 2
    m
    p
    • 3
    • 3
  • o

    oday

    06/03/2020, 12:32 PM
    i want to find an object inside items whose
    item.itemValue
    is equal to createSearchParams?.condition? and set the toggled status of that item to true
    d
    • 2
    • 2
  • e

    Evan R.

    06/03/2020, 12:44 PM
    You might want this if you want to mutate the original list.
    .map()
    creates a copy of the original list
    Untitled
    o
    m
    • 3
    • 9
  • o

    oday

    06/03/2020, 6:52 PM
    why not the string after
    ?:
    ?
    s
    • 2
    • 3
  • r

    Ryan

    06/04/2020, 11:55 AM
    i’m a big fan of never using lateinit
    m
    m
    +2
    • 5
    • 8
  • v

    Vampire

    06/05/2020, 9:07 AM
    Is there a better way to achieve this:
    enum class Boo(private val fooDelegate: String? = null) {
        BAZ,
        BAM(fooDelegate = "bar");
    
        val foo: String
            get() = fooDelegate ?: error("no foo set for ${javaClass.simpleName}.${name}")
    }
    I want that if
    foo
    is needed, it must have been set, but if it is not used, it is not necessary to set it. Optimally I like to access it by name
    foo
    and also set it by name
    foo
    instead of setting it by name
    fooDelegate
    or
    optionalFoo
    . When getting
    foo
    , I want it to be of type
    String
    though, not
    String?
    .
    t
    b
    • 3
    • 47
  • w

    waltermcq

    06/05/2020, 3:05 PM
    Is there a way to make a "javadoc" out of kotlin code?
    r
    • 2
    • 1
  • w

    waltermcq

    06/05/2020, 3:06 PM
    How would I do this in IntelliJ? Is this possible?
    a
    t
    • 3
    • 2
  • v

    Vampire

    06/05/2020, 6:38 PM
    Given these few lines:
    open class A
    interface B
    class AB: A(), B
    class CD: A(), B
    fun <T> foo(t: T): Nothing? where T : A, T : B = null
    val a = foo(AB())
    val b = listOf(AB()).map(::foo)
    val c = listOf(AB(), CD()).map(::foo)
    The last one with
    c
    is not compiling. Does anyone have an idea how to make the last line also work? It gives the compilation error
    Type parameter bound for T in fun <T : A> foo(t: T): Nothing? where T : B is not satisfied: inferred type Any is not a subtype of A
    So it seems while the created list could be of needed types
    A
    and
    B
    , the type inference is not smart enough here but creates a
    List<Any>
    Is there a way to fix this, e. g. to explicitly define the List type somehow? Interestingly the type inference in IntelliJ is smart enough to handle it properly and does not show an error, only the compiler bails out.
    k
    • 2
    • 7
  • s

    Sudhir Singh Khanger

    06/06/2020, 11:14 AM
    Could somebody ELI5 the difference between KMP and Native?
    f
    m
    • 3
    • 3
  • v

    v79

    06/06/2020, 2:58 PM
    I find myself wishing for a
    union
    type - I know it's not coming. Can anyone think of a less verbose way of implementing these combination of sealed classes?
    val modifiers: MutableMap<String,Attribute> = mutableMapOf()
    sealed class Attribute {
    	data class fValue(val value: Float) : Attribute() {
    		override fun toString(): String {
    			return value.toString()
    		}
    	}
    	data class iValue(val value: Int): Attribute()	{
    		override fun toString(): String {
    			return value.toString()
    		}
    	}
    	data class sValue(val value: String): Attribute() {
    		override fun toString(): String {
    			return value.toString()
    		}
    	}
    	data class bValue(val value: Boolean): Attribute() {
    		override fun toString(): String {
    			return value.toString()
    		}
    	}
    	data class lValue(val value: Long) : Attribute() {
    		override fun toString(): String {
    			return value.toString()
    		}
    	}
    }
    k
    m
    • 3
    • 9
  • o

    oday

    06/08/2020, 7:22 AM
    if it’s null i want to return addSearch(carsListingParameters) without the map, hmmm but those are two different datatypes then ..
    j
    • 2
    • 1
  • d

    Dominick

    06/09/2020, 5:33 AM
    I'm extremely new to Kotlin and usually code using Java. I'm using a few resources and they refer to a type of function called a top-level function. Does this mean instead of Util classes in Kotlin you would have top-level utility functions?
    :yes: 5
    m
    • 2
    • 1
  • w

    Wesley Acheson

    06/09/2020, 1:00 PM
    Hello at all. I've got some java objects that I'd need to convert to kotlin. Is there an idiomatic way of specifying constraints on data classes. Like the following Java:
    public class TotallyMadeUpClass{
        private String username
        public String getUsername(){ return this.username }
        public void setUsername(String username) {
            if (username.length > 10)
            throw new IllegalArgumentException()
            this.username = username}
    }
    r
    p
    m
    • 4
    • 13
  • b

    Bruce McLaren

    06/10/2020, 4:11 PM
    Hello all. Is there a channel to discussion Kotlin Native?
    s
    • 2
    • 2
Powered by Linen
Title
b

Bruce McLaren

06/10/2020, 4:11 PM
Hello all. Is there a channel to discussion Kotlin Native?
s

Shawn

06/10/2020, 4:15 PM
#kotlin-native
please use the Channel browser or search using the search box at the top of the Slack window.
View count: 4