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

    feroz_baig

    10/03/2017, 6:45 PM
    how can i do
    dataList?.size+1 ?: 0
    basically, if datalist isnt null, return its size+1. else, 0
    k
    s
    +3
    • 6
    • 32
  • j

    jlleitschuh

    10/03/2017, 10:09 PM
    interface SwitchMessageConverterKotlin<T>  {
        val supportedType: Class<T>
            get() = supportedKlass.java
    
        val supportedKlass: KClass<T> // Anyone know why the compiler complains about this `T`?
    }
    i
    • 2
    • 1
  • k

    kirillrakhman

    10/04/2017, 7:56 AM
    Interesting
    class Foo: (key: String) -> String
    gives an error "Unsupported: named parameter in function type in supertype position", but
    typealias KeyFunction = (key: String) -> String
    class Foo: KeyFunction
    actually works. The benefit is that when you let IDEA generate the missing members, the parameter name is set to
    key
    instead
    p1
    🤔 1
    e
    • 2
    • 4
  • o

    Olekss

    10/04/2017, 9:11 AM
    in reality what would I need is some sort of pattern matching DSL across given JSON
    g
    • 2
    • 1
  • s

    s.luhmirins

    10/04/2017, 11:40 AM
    is there a function in std-lib for cases like this?
    .let {
        when (it) {
            // ...
        }
    }
  • m

    myanmarking

    10/04/2017, 12:33 PM
    guys i need an advice, i know its not kotlin specific but maybe some1 can help. Is there any way to wrap a retrofit error response into an exception?. The errors response json is like this:
    {
      "code": "K_PRO_BE_ERR_REGIST_INVAL_USER_AGE",
      "message": "Age requirement was not respected."
    }
    :stackoverflow: 4
    f
    • 2
    • 1
  • r

    rwachol

    10/04/2017, 1:23 PM
    so I will ask something kotlin related 😉 Will kotlin support java9 runtimes? meaning, will I be able to create very minimal javafx kotlin app ?
    k
    o
    • 3
    • 2
  • j

    jb

    10/04/2017, 4:46 PM
    anyone here using Kotlin for web development on a regular basis? I'm really interested in using it in this space, but curious what others are using as the platform (outside of Kotlin itself)
    d
    h
    +2
    • 5
    • 6
  • k

    karelpeeters

    10/05/2017, 5:39 AM
    Just like in Java, you syncronize on the value,
    true
    or
    false
    , not on the variable. For this reason it's a really bad idea to ever use a primitive for synchronization.
    j
    • 2
    • 17
  • l

    lovis

    10/05/2017, 8:56 AM
    wasn’t there a keep/issue to support
    it
    inside
    when
    ? what’s the status? i can’t find it 🤔
    g
    k
    +2
    • 5
    • 16
  • f

    Fré Dumazy

    10/05/2017, 10:24 AM
    Hi, I was wondering, is there something shorter for
    CharSequence.takeIf { it.isNotBlank() }?.let { doSomethingWithThis(it) }
    to execute code only if a String or CharSequence is not null or blank?
    n
    g
    e
    • 4
    • 9
  • j

    jh

    10/05/2017, 11:21 AM
    Is there anything in the stdlib that allows zipping two collections together, but padding the result with nulls if one collection is shorter? Kind of like
    fun <T, R> Iterable<T>.zipPadded(other: Iterable<R>): List<Pair<T?,R?>>
    i
    • 2
    • 4
  • c

    Czar

    10/05/2017, 11:26 AM
    I have a feature proposal, want to hear some feedback before posting to YT: Let's say we have this interface:
    fun <E : Entity, ID : Serializable> getRequired(id: ID): E
    We can use it either like a)
    getRequired<SomeEntity,Long>(1L)
    or b)
    val entity: SomeEntity = getRequired(1L),
    It seems to me that case a) is unnecessarily verbose, I'd like to write
    getRequired<SomeEntity>(1L)
    , because
    1L
    already contains information about type of the second generic parameter, so compiler can infer it, like it does in case b).
    i
    k
    b
    • 4
    • 5
  • j

    jschneider

    10/05/2017, 12:12 PM
    `` @Symbol( AM.SYMBOL ) @Definition( {"optical path length through Earth's atmosphere", "relative to path length to that at the zenith at sea level"} ) public @interface AM { String SYMBOL = "AM"; } ``
  • j

    jschneider

    10/05/2017, 12:27 PM
    That is a little bit disappointing. I hoped that I can do everything with Kotlin that is possible with Java. I try to convert my Java code to Kotlin. But at some points that is not possible without breaking backwards compatibility 😞
    i
    • 2
    • 1
  • j

    joao.alves

    10/05/2017, 1:38 PM
    Hello everyone. Is there anyone interested in Droidcon London tickets? Droidcon is happening on October 26-27th 2017. Since my company is sponsoring the event we have some extra tickets, so we have 3 personal tickets we don’t need anymore and we would like to give them away for the price we purchased them. The price is £250 each. They’re selling for £774 on the website now and will be an extra £50 after the 13th.
    k
    • 2
    • 2
  • p

    pablisco

    10/05/2017, 7:35 PM
    I'm trying to find information about how to use Kotlin annotations in Java. But I can't find the right search. Are they fully compatible?
    a
    • 2
    • 2
  • k

    karelpeeters

    10/06/2017, 5:56 AM
    The kotlin compiler detects annotations and assumes the corresponding nullability @qwert_ukg.
    q
    • 2
    • 1
  • f

    Fré Dumazy

    10/06/2017, 8:10 AM
    Hi, I'm having some problems with generics: How do I create a method that accepts
    <T: MyObject> myMethod(arg: MyWrapper<T>)
    and
    <T: MyObject> myMethod(arg: MyWrapper<Array<T>>)
    If I try this in 2 methods with the same name, it says "The following declarations have the same JVM signature"
    d
    k
    +2
    • 5
    • 6
  • m

    marstran

    10/06/2017, 11:45 AM
    I would make immutable data classes, and use copy:
    val newObj = obj1.copy(name = obj2.name, ....)
    .
    👍 3
    q
    • 2
    • 5
  • j

    jcogilvie

    10/06/2017, 4:05 PM
    fair point. basically this is ported from a java String.format() call, which is more efficient than string literal concats iirc, so I guess I'm still trying to avoid the latter. not sure if kt improves java in that regard?
    h
    • 2
    • 2
  • o

    orangy

    10/06/2017, 8:42 PM
    We have #rant in our JetBrains’ internal Slack 🙂
    👍 1
    r
    • 2
    • 7
  • a

    ayrat555

    10/07/2017, 9:00 AM
    Are coroutines replacement for java 8's completable future?
    k
    s
    • 3
    • 2
  • g

    geekasm

    10/07/2017, 9:56 AM
    open class dmap( val map : Map< String, Any > )
    
    inline fun <T : dmap, reified TValue : dmap> T.dmap(): ReadOnlyProperty<T, TValue> {
        return object : ReadOnlyProperty<T, TValue> {
            override fun getValue(thisRef: T, property: KProperty<*>) = TValue( thisRef.map[property.name] ) )
        }
    }
    p
    • 2
    • 1
  • c

    christophsturm

    10/08/2017, 9:07 AM
    must be a very powerful lib if you are using it despite its api
    g
    b
    • 3
    • 4
  • s

    Shawn

    10/09/2017, 3:24 PM
    Nobody is arguing against using early returns at all. What we are a bit concerned about is the fact that this code snippet is pretty hard to interpret, and that in of itself may warrant rewriting this block to be more easily understood. That said, sure, in a vacuum “style” does not solve your problem, but it does make it harder to give you advice. Based on your initial snippet, I would suggest something that looks more like this:
    when (i) {
      in 0..10 -> println("matched")
      else -> println("not matched")
    }
    println("finished")
    n
    • 2
    • 3
  • j

    jw

    10/10/2017, 4:17 AM
    .map(::MyClass)
    q
    e
    +2
    • 5
    • 6
  • p

    Paul Woitaschek

    10/10/2017, 8:41 AM
    @Kulwinder Singh Please don't crosspost
    k
    k
    • 3
    • 3
  • e

    edwardwongtl

    10/10/2017, 9:40 AM
    Can you post some of the
    build.gradle
    code up here?
    k
    • 2
    • 1
  • g

    gildor

    10/10/2017, 9:41 AM
    Is that just IDE message or you have problems with build or code highlighting?
    k
    • 2
    • 1
Powered by Linen
Title
g

gildor

10/10/2017, 9:41 AM
Is that just IDE message or you have problems with build or code highlighting?
k

Karolo

10/10/2017, 9:51 AM
code is all red underlined. Cannot resolve even the most basic android classes 😄
View count: 1