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

    sigmadelta

    08/02/2017, 9:59 AM
    Hey guys, I’ve been using Kotlin for about 5 days now and while I feel pretty comfortable writing it, I can’t help but get the feeling that I’m basically writing Java in the Kotlin syntax. How do I get over this barrier and make sure that I’m actually making best use of what Kotlin has to offer over Java?
    d
    v
    • 3
    • 2
  • t

    techie01

    08/02/2017, 10:15 AM
    what is difference b/w hashmapOf and mapOf in kotlin
    v
    • 2
    • 3
  • d

    diesieben07

    08/02/2017, 11:40 AM
    The idiomatic way would be to use the
    Array
    constructor:
    Array(3) { index -> value }
    , which initializes the array immediately, so you can have a non-null component type.
    👍 1
    h
    • 2
    • 7
  • t

    techie01

    08/02/2017, 11:43 AM
    how to use gradle for kotlin programming
    a
    • 2
    • 1
  • d

    dekans

    08/02/2017, 2:44 PM
    maybe
    iAmAVar?.let{ it+"XXX" } ?: "XXX"
    h
    d
    • 3
    • 9
  • d

    denis.shakinov

    08/02/2017, 4:15 PM
    See no point either. @dniHze why wouldn't you just place interface on the same level as your inner class?
    a
    • 2
    • 6
  • o

    oday

    08/03/2017, 10:02 AM
    where can I see a list of all the functions that work on Collections?
    h
    x
    • 3
    • 6
  • h

    horse_badorties

    08/04/2017, 6:36 AM
    How do I get to the actual stdlib-sources of - say - the
    min()
    function in Intellij? When I do
    STRG-B
    it loads
    _Collections.kt
    from the
    generated
    folder of the
    kotlin-stdlib-xxx-sources.jar
    - which is not the actual source I guess. When I browse the
    kotlin\collections
    folder instead I find CollectionsKt.class but this does not include the
    min()
    function. A "Search everywhere" doesn't help either. What is this
    generated
    folder about anyway? Who generates it and why? 😅
    i
    • 2
    • 2
  • o

    oday

    08/04/2017, 10:20 AM
    how do I initialize a queue?
    k
    • 2
    • 3
  • t

    techie01

    08/04/2017, 10:46 AM
    what is meant by asychronous programming
    f
    b
    • 3
    • 3
  • k

    kevinmost

    08/04/2017, 9:59 PM
    a lint warning for `IntRange`s where the lower bound is higher than the higher bound might be useful
    ➕ 1
    r
    • 2
    • 1
  • v

    voddan

    08/05/2017, 6:06 AM
    @horse_badorties @johnaqel This limitation of
    ..
    is made so to emulate the traditional
    for
    loop. In a code
    for(int i = A; i < B; i++){}
    nothing happens if
    A
    is greater than
    B
    . This is how programmers are accustomed to think about iterations. If the
    ..
    loop worked both ways, the number of bugs would be colossal.
    h
    k
    • 3
    • 5
  • o

    oday

    08/05/2017, 9:17 PM
    also, whoever linked me to this video

    https://www.youtube.com/watch?v=AhA-Q7MOre0&amp;list=PLtRrDEpV3zktLTZlkx0CPqyIYQ4Z9m7v0&amp;index=5▾

    it’s way too complex, is there a better introduction example for functional programming for Kotlin?
    n
    • 2
    • 1
  • d

    danneu

    08/05/2017, 11:12 PM
    anyone know what i'm talking about and what i'd look into for changing it so that intellij waits til i tell it to build or at least waits til i save build.gradle?
    j
    • 2
    • 3
  • o

    oday

    08/06/2017, 11:18 AM
    how would I go about implementing this
    v
    b
    • 3
    • 11
  • b

    benleggiero

    08/06/2017, 10:33 PM
    Why won't this compile?
    open class Queue<Element>(protected var backingList: MutableList<Element> = mutableListOf()) {
        fun listValue():List<Element> = List(*(backingList.toTypedArray().copyOf()))
    }
    Error:
    Error:(44, 56) Kotlin: Cannot use 'Element' as reified type parameter. Use a class instead.
    e
    • 2
    • 4
  • t

    techie01

    08/07/2017, 11:36 AM
    how to add two nullable values
    m
    s
    v
    • 4
    • 7
  • t

    techie01

    08/07/2017, 2:21 PM
    how to print list of collection names by using kmongo
    :stackoverflow: 4
    v
    • 2
    • 1
  • s

    stefano.maffullo

    08/07/2017, 5:09 PM
    I think you can override it and make it return every string you want 😅
    v
    • 2
    • 1
  • e

    eldamsheety

    08/08/2017, 1:05 PM
    Which one should I learn, JavaFx or TornadoFx?
    d
    r
    • 3
    • 5
  • t

    techie01

    08/08/2017, 2:23 PM
    how to get it for free
    o
    h
    w
    • 4
    • 7
  • h

    horse_badorties

    08/09/2017, 7:44 AM
    is there a
    java.util.EnumSet
    equivalent in Kotlin? If not (how) can I use it with a Kotlin
    enum class
    ?
    e
    j
    • 3
    • 4
  • v

    v79

    08/09/2017, 9:19 AM
    Are data classes any lighter on the JVM to instantiate and use? Or are they just a programmer's convenience?
    e
    • 2
    • 1
  • i

    infini

    08/09/2017, 1:00 PM
    your brackets look off - what happens if you do mode?.equals
    n
    a
    +2
    • 5
    • 13
  • c

    chet

    08/10/2017, 6:36 AM
    Hi all, I'm kotlin beginner, regarding the "when expression", is it just a powerful switch case, or does pattern matching also? You can only check types/values or you can destructure variables also? Use of when expression with sealed classes almost look like it may be some form of pattern matching expression?
    d
    • 2
    • 2
  • b

    brokenpipe

    08/10/2017, 8:14 AM
    Hi, how can I define secondary constructor calling it's super constructor? eg.
    b
    • 2
    • 1
  • m

    mcscruff

    08/10/2017, 10:46 AM
    im a little stuck, i have a mutable map with Names as a key and address's as a value, is it possible to "get" the key and value at any given index. For example, if i wanted to know the 6th in the map
    d
    m
    m
    • 4
    • 8
  • m

    mcscruff

    08/10/2017, 11:05 AM
    also, is there plans to build a ChromeOS / Android version of IntelliJ
    k
    • 2
    • 1
  • t

    techie01

    08/10/2017, 11:59 AM
    can we convert json to xml
    s
    k
    • 3
    • 3
  • a

    ar-g

    08/10/2017, 12:51 PM
    How to define object inside sealed generic hierarchy?
    sealed class PaginationViewState<T> {
        object LoadingFirstPage: PaginationViewState<T>()//doesn't work
        object LoadingPage: PaginationViewState<T>()//doesn't work
    
        data class DataLoaded<T>(val data: List<T>): PaginationViewState<T>()
        data class DataLoadedFromCache<T>(val data: List<T>): PaginationViewState<T>()
        data class Failure<T>(val e: Throwable): PaginationViewState<T>()
    }
    m
    • 2
    • 13
Powered by Linen
Title
a

ar-g

08/10/2017, 12:51 PM
How to define object inside sealed generic hierarchy?
sealed class PaginationViewState<T> {
    object LoadingFirstPage: PaginationViewState<T>()//doesn't work
    object LoadingPage: PaginationViewState<T>()//doesn't work

    data class DataLoaded<T>(val data: List<T>): PaginationViewState<T>()
    data class DataLoadedFromCache<T>(val data: List<T>): PaginationViewState<T>()
    data class Failure<T>(val e: Throwable): PaginationViewState<T>()
}
m

marstran

08/10/2017, 12:54 PM
You need to specify a
T
for your objects.
By the way, after Kotlin 1.1, you don't need to nest the classes and objects inside the sealed class. They just have to be in the same file.
a

ar-g

08/10/2017, 12:55 PM
no, type parameters not allowed
m

marstran

08/10/2017, 12:56 PM
The
T
has to be an actual class/interface here:
object LoadingFirstPage : PaginationViewState<T>()
No type parameters allowed? What do you mean? You have specified
PaginationViewState
with a type parameter.
a

ar-g

08/10/2017, 12:57 PM
not allowed in this statement
object LoadingFirstPage<T>: PaginationViewState<T>()
m

marstran

08/10/2017, 12:57 PM
That doesn't work because there is only one instance of
LoadingFirstPage
. It can't take parameters.
Maybe
LoadingFirstPage
should be a class then?
a

ar-g

08/10/2017, 12:58 PM
that is what I did😀
m

marstran

08/10/2017, 1:09 PM
It looks like that should be the correct solution for you looking at your example.
T
is the type of data that the view state holds, so
LoadingFirstPage
and
LoadingPage
are classes, not objects.
I see you are writing on the StackOverflow post that using
Any
is what you were looking for. I really don't think you should do that. You are losing type information that you don't have to lose.
👍 1
a

ar-g

08/10/2017, 1:21 PM
yes, it is meaningless since I can't define class with desired type
PaginationViewState<AdModel> =PaginationViewState.LoadingFirstPage
. I'll stick with regular classes probably
m

marstran

08/10/2017, 1:46 PM
You can still have (and you should have) a sealed class hierarchy though.
View count: 5