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
android
  • w

    w_bianrytree

    07/11/2017, 5:09 PM
    change log come out?
    m
    1 reply · 2 participants
  • s

    skennedy

    07/11/2017, 8:06 PM
    hmmm i seem to be having major issues with kotlin in AS 3.0 canary 6
    b
    e
    +1
    13 replies · 4 participants
  • a

    ansari

    07/11/2017, 10:25 PM
    hello does anyone have idea about retrofit @ get request header ?
    k
    13 replies · 2 participants
  • k

    kostya1375

    07/12/2017, 8:35 AM
    well String import was unwanted..
    l
    1 reply · 2 participants
  • a

    arnaud.giuliani

    07/12/2017, 9:37 AM
    I've just created #koin to speak about koin framework (https://github.com/Ekito/koin)
    t
    4 replies · 2 participants
  • t

    tschuchort

    07/12/2017, 12:47 PM
    what type should be used for `Observable`s that don't really have a type? I wanna use
    Unit
    of course, but are there any disadvantages to using
    Unit
    ? Most online resources (in Java) seem to use
    Void
    , which I can't even instantiate to call
    onNext
    in my
    Observable.create()
    h
    1 reply · 2 participants
  • b

    bachhuberdesign

    07/12/2017, 8:26 PM
    Anyone having random freezing every once in a while in Android Studio canary 6? I’ve been using 3.0 since canary 1 but this is the first time I’ve been getting consistent freezes (on macOS)
    s
    k
    2 replies · 3 participants
  • g

    gildor

    07/13/2017, 9:42 AM
    Also, I don’t understand why do you need lambda for
    message
    , you can replace it with
    String
    j
    1 reply · 2 participants
  • g

    gildor

    07/13/2017, 9:43 AM
    fun Fragment.showShortSnackbar(message: String) {
        val activity = activity ?: return
        Snackbar.make(activity.findViewById(android.R.id.content), message, Snackbar.LENGTH_SHORT).show()
    }
  • d

    damien5314

    07/13/2017, 5:13 PM
    @anthaugh sometimes i just add a wildcard to a dependency, see what version gets resolved, then swap out the wildcard for that version 😅 not very ideal though, and sometimes it picks up snapshots/betas
    a
    3 replies · 2 participants
  • o

    oscarg798

    07/14/2017, 1:32 AM
    myString?.let{ mTextview.text = myString }
    v
    m
    +2
    9 replies · 5 participants
  • g

    gabrielfv

    07/14/2017, 9:06 PM
    Moving to Kotlin team??
    o
    1 reply · 2 participants
  • k

    kevinmost

    07/14/2017, 9:14 PM
    a different kind of
    fun
    😂 4
    👍 1
    o
    1 reply · 2 participants
  • o

    orangy

    07/15/2017, 11:39 PM
    I think @jw will post what are his plans when he finds it is right time to do so.
    👏 1
    ☝️ 8
    😆 4
    👈 2
    😬 1
    i
    4 replies · 2 participants
  • m

    morozov

    07/16/2017, 3:08 PM
    who can help me with implementations google map view in my bottom sheet? I have a separate implementation google map and bottom sheet Who can help to connect them? please
    o
    e
    2 replies · 3 participants
  • l

    leosan

    07/17/2017, 9:51 AM
    Hi anyone could help me with how to use Kotlin + Dagger2 + Generics? I have a
    @Provides Foo<*>
    and then
    @Provides Presenter(Foo<Bar>)
    But this gives me an error
    Foo<Bar> cannot be provided without an @Inject or @Provides-annotated method
    😞 I've tried this already
    @Provides Presenter(Foo<@JvmSupressWildcards Bar>)
    but without Success
    d
    4 replies · 2 participants
  • p

    Paul Woitaschek

    07/18/2017, 10:13 AM
    Each subsequent subscription will cancel the previous returned observable
    g
    1 reply · 2 participants
  • n

    norman784

    07/18/2017, 12:34 PM
    I still doesn't understand why people choose to use RxJava (Kotlin in this case), I'm not here to start a flame war, b/c I really never used it but read some articles about it and didn't found it useful or easy to use
    s
    i
    +2
    4 replies · 5 participants
  • b

    bamdmux

    07/19/2017, 8:55 AM
    @morozov Use
    mutableListOf<AnimalPlanet>()
    if you pretend to add elements later
    m
    1 reply · 2 participants
  • m

    morozov

    07/19/2017, 8:55 AM
    @gildor but if i need to create for example 100 elements, i need to use range instead
    for
    ?
    g
    1 reply · 2 participants
  • b

    bamdmux

    07/19/2017, 9:05 AM
    (1..100).map { i -> AnimalPlanet( __use i here__) }
    👍 1
    m
    g
    4 replies · 3 participants
  • b

    bamdmux

    07/19/2017, 9:42 AM
    @morozov If i understand what you are trying to do, you can use
    somevalue.coerceAtLeast(0F)
    m
    2 replies · 2 participants
  • p

    Paul Woitaschek

    07/19/2017, 10:06 AM
    I get a warning with "Access can be private" for an @Inject annotated field
    l
    2 replies · 2 participants
  • t

    thubi

    07/19/2017, 1:24 PM
    and all jarfiles are in the libs directory
    e
    3 replies · 2 participants
  • g

    gregd

    07/19/2017, 8:43 PM
    @blakelee Ask on the #rx channel, along with some code example
    🙂 1
    b
    2 replies · 2 participants
  • d

    diego-gomez-olvera

    07/20/2017, 8:24 AM
    - Help create compelling Kotlin APIs that allow developer to create powerful and efficient applications with ease. - Help define Kotlin best practices for Android development.
    o
    2 replies · 2 participants
  • j

    jordan29.04.1197

    07/20/2017, 9:12 AM
    Hi all, Can you help me?
    val dialogAvatarSource = DialogAvatarSource(this)
            dialogAvatarSource.onAvatarSourceChosenListener = object : DialogAvatarSource.OnAvatarSourceChosenListener {
                override fun onCameraClick() {
    
                }
    
                override fun onGalleryClick() {
    
                }
            }
            dialogAvatarSource.show()
    java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter savedInstanceState on dialogAvatarSource.show()
    m
    3 replies · 2 participants
  • s

    szymen

    07/21/2017, 12:01 PM
    Why kotlin-android-extensions plugin doesn't cache views inside custom view?
    m
    3 replies · 2 participants
  • p

    Paul Woitaschek

    07/21/2017, 1:22 PM
    @budioktaviyan What do you mean by that?
    b
    1 reply · 2 participants
  • m

    matt_dziubek

    07/24/2017, 8:27 AM
    Hi guys, I’ve got a problem with Kotlin, which involves generics. Stick with me though 😉. I have a below generic interface:
    interface RecyclerItem<in T : RecyclerView.ViewHolder> {
    
        fun onBindViewHolder(holder: T?)
    }
    Generic is defined as
    in
    because clearly
    RecyclerItem
    is a consumer, hence I can only assign this instance to its subtype. I also have a below implementations of `RecyclerItem`:
    class ItemSuncalcData() : RecyclerItem<ItemSuncalcData.ViewHolder>
    and:
    class SomeOtherItem() : RecyclerItem<SomeOtherItem.ViewHolder>
    Long story short I want to store above two instances in a
    List<RecyclerItem<RecyclerView.ViewHolder>>
    , but because of
    in T
    I can’t assign subclasses to its supertypes. What’s my best move here? I’ve written same code in java and only got unchecked cast warning. The only way I could think of was to remove generics from the interface:
    interface RecyclerItem {
    
        fun onBindViewHolder(holder: RecyclerView.ViewHolder?)
    }
    But before I’ll change 15+ files (because of casting I would have to make) I wanted to ask you first, thanks in advance 😉 Take a look at this github repo I made showcasing my problem above: https://github.com/matdziu/GenericsKotlin. You can switch between two commits - one that uses generic way (compilation error in MainActivity) and the second which is the solution I think I found. Note that on production we’re using multiple different item types and factory pattern to choose a proper view holder (this sample is just a huge simplification).
    m
    4 replies · 2 participants
Powered by Linen
Title
m

matt_dziubek

07/24/2017, 8:27 AM
Hi guys, I’ve got a problem with Kotlin, which involves generics. Stick with me though 😉. I have a below generic interface:
interface RecyclerItem<in T : RecyclerView.ViewHolder> {

    fun onBindViewHolder(holder: T?)
}
Generic is defined as
in
because clearly
RecyclerItem
is a consumer, hence I can only assign this instance to its subtype. I also have a below implementations of `RecyclerItem`:
class ItemSuncalcData() : RecyclerItem<ItemSuncalcData.ViewHolder>
and:
class SomeOtherItem() : RecyclerItem<SomeOtherItem.ViewHolder>
Long story short I want to store above two instances in a
List<RecyclerItem<RecyclerView.ViewHolder>>
, but because of
in T
I can’t assign subclasses to its supertypes. What’s my best move here? I’ve written same code in java and only got unchecked cast warning. The only way I could think of was to remove generics from the interface:
interface RecyclerItem {

    fun onBindViewHolder(holder: RecyclerView.ViewHolder?)
}
But before I’ll change 15+ files (because of casting I would have to make) I wanted to ask you first, thanks in advance 😉 Take a look at this github repo I made showcasing my problem above: https://github.com/matdziu/GenericsKotlin. You can switch between two commits - one that uses generic way (compilation error in MainActivity) and the second which is the solution I think I found. Note that on production we’re using multiple different item types and factory pattern to choose a proper view holder (this sample is just a huge simplification).
m

mzgreen

07/24/2017, 8:35 AM
Have you tried
List<RecyclerItem<*>>
?
m

matt_dziubek

07/24/2017, 8:50 AM
yes, didn’t work
could you look at my sample and confirm?
m

mzgreen

07/24/2017, 9:13 AM
class RecyclerView{
    interface ViewHolder
}

interface RecyclerItem<in T : RecyclerView.ViewHolder> {
     fun onBindViewHolder(holder: T?)
} 

class ItemTextView : RecyclerItem<ItemTextView.ViewHolder> {

    override fun onBindViewHolder(holder: ViewHolder?) {}

    class ViewHolder : RecyclerView.ViewHolder {}
}

fun main(args: Array<String>) {
	
    val list = mutableListOf<RecyclerItem<*>>()
    list.add(ItemTextView())
    
    println(list.size) // prints 1
}
View count: 1