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
announcements
  • j

    Jon White

    04/02/2018, 10:57 PM
    Can anyone recommend where to read up on current best practices for asynchronous requests? Should I look into co-routines and observables as well? Essentially, I want to build an async request library that's as fast as possible and can scale as needed. Where can I find out more about the state of the art?
    s
    2 replies · 2 participants
  • b

    burg

    04/02/2018, 11:55 PM
    is anyone able to help me understand this question I posted on SO? https://stackoverflow.com/questions/49620173/why-does-kotlin-kclasst-have-a-bound-generic-type-of-any
    ➕ 1
    s
    l
    10 replies · 3 participants
  • f

    frellan

    04/03/2018, 5:55 AM
    This:
    constructor(
        title: String,
        portions: Int,
        sections: List<ClassA>,
        sourceUrl: String? = null
      )
    and this:
    constructor(
        title: String,
        portions: Int,
        ingredients: List<ClassB>,
        sourceUrl: String? = null
      )
    Apperently have the same JVM signature, why is that? Can’t it see that
    ClassA
    and
    ClassB
    are two different classes in the list? I did not know that two lists with different content looked the same to the bytecode
    a
    g
    +1
    11 replies · 4 participants
  • a

    aeruhxi

    04/03/2018, 9:21 AM
    yep, I have it in dependency.
    g
    1 reply · 2 participants
  • r

    Robert White

    04/03/2018, 10:05 AM
    Has anyone used SBT alongside Kotlin? I was taking a look at https://github.com/pfn/kotlin-plugin (as my team likes using SBT and was thinking about smallest migration path) but it doesn’t seem to work any more.
    e
    1 reply · 2 participants
  • r

    robstoll

    04/03/2018, 11:06 AM
    is there a way to get the start position of a MatchResult as it is possible for java.util.regex.Matcher?
    d
    2 replies · 2 participants
  • s

    spand

    04/03/2018, 12:01 PM
    Yes but trying to emulate it I think I got an error declaring stuff in
    kotlin.internal
    d
    3 replies · 2 participants
  • d

    diesieben07

    04/03/2018, 12:23 PM
    Just tried it out and it actually does work for me. So... I'll stick with it for now...
    g
    s
    6 replies · 3 participants
  • z

    ziggy42

    04/03/2018, 6:57 PM
    Is it considered okey to define JUnit tests like this:
    @Test 
    fun `do something here`() {
    
    }
    d
    a
    3 replies · 3 participants
  • r

    rednifre

    04/03/2018, 7:20 PM
    What's a simple and cool testing framework for kotlin?
    a
    a
    +7
    16 replies · 10 participants
  • f

    frellan

    04/04/2018, 3:43 AM
    Question: Where should one declare typealiases exactly? I want to use that alias everywhere in my code I guess, where do I define an alias? What is a common pattern?
    w
    1 reply · 2 participants
  • d

    diesieben07

    04/04/2018, 9:03 AM
    Are the individual lines really too long to be read at once?
    p
    1 reply · 2 participants
  • m

    mplacona

    04/04/2018, 2:04 PM
    Hey all, quick question as I can't find any solid resources for this. How does one test extension methods? Say I have something like
    fun Date.isWeekend() = day == 6 || day == 7
    Inside a class. How do I go about unit testing this?
    a
    k
    2 replies · 3 participants
  • j

    jw

    04/04/2018, 2:09 PM
    the same way you would a method with the signature
    fun isWeekend(date: Date): Boolean
    m
    d
    11 replies · 3 participants
  • k

    karelpeeters

    04/04/2018, 3:50 PM
    And without a double lazy implementation!
    u
    3 replies · 2 participants
  • k

    karelpeeters

    04/04/2018, 3:53 PM
    lazyGey
    is redundant,
    get
    is already lazy.
    u
    1 reply · 2 participants
  • k

    karelpeeters

    04/04/2018, 3:55 PM
    Ie. return the previous instace if it exists and otherwise create a new one and remember it.
    u
    7 replies · 2 participants
  • n

    nekoinemo

    04/04/2018, 5:59 PM
    Sorry for the potentially silly question, but if i make an extension property by delegate... Where does delegate's data get stored? Do i create one delegate that just operates on generic receiver? Or does it results in new instance being produced for every receiver? How exactly does that all work?
    i
    2 replies · 2 participants
  • c

    chetsachdeva

    04/04/2018, 7:11 PM
    Hi Kotlin folks! I’m trying to parse a hexadecimal color. Input is
    String
    like
    "0xFF3F51B5"
    and I need to use it in
    button.setBackgroundColor(int: Int)
    . I’ve tried
    Integer.decode(hexString)
    and
    hexString.toInt(radix = 16)
    but no success. Looks like there’s an overflow: https://youtrack.jetbrains.com/issue/KT-4749 Please help. Thanks 🙂
    m
    2 replies · 2 participants
  • v

    v79

    04/04/2018, 7:26 PM
    And I've just realised I can use default parameters to achieve what I want, I think 🙂
    1 reply · 1 participant
  • c

    chetsachdeva

    04/04/2018, 7:29 PM
    I don’t understand the primary constructor solution. Lemme try
    hexString.toLong(16).toInt()
    meanwhile 👍
    r
    k
    5 replies · 3 participants
  • e

    Eugen Martynov

    04/04/2018, 7:47 PM
    isn’t it for avoiding overloading
    a
    s
    3 replies · 3 participants
  • c

    Clayton Walker

    04/04/2018, 8:02 PM
    in this case your example is nasty because ({}) implicitly sets the first non-default parameter, and in the {} case it's using the last lambda parameter.
    a
    e
    5 replies · 3 participants
  • s

    snowe

    04/04/2018, 10:34 PM
    We'd like to just check if propertyId is set, and if it isn't then get the propertyId of the
    property
    object.
    a
    3 replies · 2 participants
  • k

    karelpeeters

    04/05/2018, 6:41 AM
    @snowe You need to use
    field
    to access the backing field, not the actual field.
    s
    4 replies · 2 participants
  • z

    ziggy42

    04/05/2018, 12:43 PM
    Someone knows how to do it?
    s
    12 replies · 2 participants
  • i

    igor.wojda

    04/05/2018, 3:20 PM
    WHat is the difference between
    Open
    and
    Submitted
    issue status on youtrack (Kotlin issue tracker)?
    l
    1 reply · 2 participants
  • p

    Paul Woitaschek

    04/05/2018, 8:11 PM
    Can I call a function with a reified type when I have the class?
    k
    1 reply · 2 participants
  • a

    adam-mcneilly

    04/05/2018, 9:29 PM
    I want to write a test that checks if a property I have is a certain type. The property is a sealed class, so I want to write something like:
    fun assertNetworkStateType(clazz: Class<*>) { assertTrue(networkState is clazz) }
    so that I can call it like
    assertNetworkStateType(NetworkState.Loading)
    but I can't quite figure out what the type of that parameter would be.
    d
    5 replies · 2 participants
  • j

    jakubgruber

    04/06/2018, 9:56 AM
    Hi, I encountered strange issues with
    JSONObject
    in Android. Can anyone help me, please?
    @Test
    fun `create JSON, must not be empty or null`() {
        val json = JSONObject()
        json.put("name", "value")
    
        assertNotNull(json)
        assertEquals("value",json.get("name"))
    }
    Running above test fails, but I believe it should not. What’s wrong with
    JSONObject
    ?
    e
    g
    23 replies · 3 participants
Powered by Linen
Title
j

jakubgruber

04/06/2018, 9:56 AM
Hi, I encountered strange issues with
JSONObject
in Android. Can anyone help me, please?
@Test
fun `create JSON, must not be empty or null`() {
    val json = JSONObject()
    json.put("name", "value")

    assertNotNull(json)
    assertEquals("value",json.get("name"))
}
Running above test fails, but I believe it should not. What’s wrong with
JSONObject
?
e

edwardwongtl

04/06/2018, 10:03 AM
I think
json.get("name")
does not give you a string but a
JSONObject
or sth
j

jakubgruber

04/06/2018, 10:04 AM
That’s definitely not a problem, because the object returned by
json.get("name")
returns null anyway
g

gildor

04/06/2018, 10:09 AM
This test passes for me
j

jakubgruber

04/06/2018, 10:13 AM
Thank you for feedback. Will check that outside unit tests.
Guess it’ll be something related to Android. I tried to turn off
testOptions {
        unitTests.returnDefaultValues = true
    }
g

gildor

04/06/2018, 10:14 AM
oh, Android, yeah I test on pure Java project
I suppose this is because you use org.json.JSONObject
and this is a part of the Android Framework
so you cannot use it in unit tests without mocking
j

jakubgruber

04/06/2018, 10:15 AM
Aaah, ok. Thank you :))
g

gildor

04/06/2018, 10:15 AM
You probably use
unitTests.returnDefaultValues = true
so instead of throwing exception you got null value as result
if
returnDefaultValues = true
in your project, my advice to disable it, otherwise you will get a lot of such hard to understand problems
to test JSONObject maybe make sense to add
org.json:json
to test dependencies and use it instead of platform one, but be careful, version of this library can be different on Android Framewrok
j

jakubgruber

04/06/2018, 10:19 AM
Yeah, I know using
returnDefaultValues = true
is not recommended, I just wanted to quickly test something with OkHttp
g

gildor

04/06/2018, 10:19 AM
Hm? OkHttp can be used without mocking, this is not a part of Android Framework and not Android library at all, you can use it without problem for unit tests
j

jakubgruber

04/06/2018, 10:20 AM
You’re right, but you cannot pass JSONObjects there then without mocking.
g

gildor

04/06/2018, 10:21 AM
Why do you need this on okhttp?
You can serialize/deserialize json using any json library in your tests
j

jakubgruber

04/06/2018, 10:22 AM
I wanted to create json, sign it and post it via okHttp
But there’s probably no reason to do that. As long as it can add
Signature
header (it can) and can post json (tested elsewhere), it must work 🙂
g

gildor

04/06/2018, 10:24 AM
also, don’t forget about old good strings:
"""{"my":"json", "object": []}"""
👍 1
j

jakubgruber

04/06/2018, 10:25 AM
Will do, thanks. The reason why I went in a more like “integration way” was that I’m still getting used to Kotlin and testing what could possible be issue and what not
View count: 7