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

    qwert_ukg

    03/15/2018, 5:56 AM
    How i can call java static methods from instance? in Java i can, but Kotlin throws UnresolvedReference 😞
    n
    • 2
    • 3
  • a

    altavir

    03/15/2018, 7:52 AM
    I think that you should never try to call static member on instance just because it confuses you. Static members are resolved statically by the class name not by member instance. For example if you have a class A inheriting B and call static function on A, when actual object is B, it will still be called on A.
    ➕ 3
    q
    n
    h
    • 4
    • 6
  • m

    Matthias Schuster

    03/15/2018, 10:07 AM
    The JVM don’t like that TCO removes stack frames while loops have no stack frames at all, so why does this matter?
    d
    • 2
    • 4
  • r

    robstoll

    03/15/2018, 12:45 PM
    Does someone know if kotlin is going to adopt jdk9 modules? I am particularly curious if it will be possible to require packages from another module without requiring transitive packages
    e
    • 2
    • 3
  • j

    jkbbwr

    03/15/2018, 2:47 PM
    Would it be worth inlining this
    fun Int.format(format: String): String {
        return String.format(format, this)
    }
    d
    • 2
    • 1
  • r

    robstoll

    03/15/2018, 4:26 PM
    IMO it is always better if the compiler can tell your intention than the documentation (which no one reads if not necessary)
    j
    r
    • 3
    • 13
  • n

    nfrankel

    03/15/2018, 10:22 PM
    generateSequence(x) { it }
    r
    d
    • 3
    • 3
  • k

    krtko

    03/16/2018, 12:05 AM
    Hey does anyone around think they could help me with a multi-platform issue?
    k
    • 2
    • 2
  • j

    jurajsolarml

    03/16/2018, 10:29 AM
    Ok, you can write me where I find it just junior programmer.Thanks
    a
    • 2
    • 5
  • e

    elect

    03/16/2018, 10:57 AM
    I'd like some feedbacks, because I have the feeling I'm gonna get bitten by this issue sooner or later. I have generic interfaces
    Vec3t<Number>
    implemented as
    Float
    ,
    Int
    , etc.. Of course methods differing only for a different type (i.e:
    dot(v: Vec3t<Number>)
    and
    dot(v: Vec3t<Float>)
    ) have the same signature, but if I try to call:
    val vert = Vec3() // Vert3 : Vec3t<Float>
    vert.dot(fromTo) // error, none of the following functions can be called. Note that dot is dot(v: Vec3t<Number>)
    I have to either change
    dot
    to
    dot(v: Vec3t<Float>)
    or create a new set of interfaces, where I have
    Vec3tNumber
    and
    Vec3tFloat
    and so on.. What do you think?
    a
    • 2
    • 17
  • e

    elect

    03/16/2018, 11:12 AM
    Probably I just needed a
    Vec3t<out Number>
    ➕ 1
    d
    • 2
    • 2
  • a

    adev_one

    03/16/2018, 11:18 AM
    Is it possible to publish a common module in maven?
    i
    • 2
    • 1
  • n

    ndv

    03/16/2018, 2:41 PM
    Hello, I have currency symbols stored by their HTML codes, and need to convert them in kotlin to the corresponding currency symbol, so
    &#x24; -> $
    - any standard library capable of doing this or do I need to build a map myself? Thanks!
    h
    m
    • 3
    • 6
  • k

    kartikpatodi

    03/16/2018, 3:43 PM
    how to create junit tests for kotlin files in intellij? is there a shortcut(key binding for that)?
  • d

    dasz

    03/16/2018, 5:28 PM
    open class Human() 
    class Men:Human()
    class Women:Human()
    val humanNation = asList(Women(), Man())
    val womenForMe = humanNation.firstOrNull{ it is Women} as Women?
    any shorter form? thank you @agrosner for the help the solution is
    inline fun <reified K:T, T> List<T>.firstOrNull(): K? = firstOrNull { it is K} as K?
    usage
    val womenForMe : Women = humanNation.firstOrNull()
    🤨 2
    z
    a
    +3
    • 6
    • 13
  • s

    stephan_marshay

    03/16/2018, 5:36 PM
    Didn't you mean
    humanNation.firstOrNull {...}
    ?
    d
    s
    • 3
    • 5
  • u

    ursus

    03/16/2018, 6:18 PM
    Hi, id like to ask concerning kotlin + rxjava
    r
    • 2
    • 1
  • u

    ursus

    03/16/2018, 6:26 PM
    and in java it does work without it aswell
    r
    f
    • 3
    • 5
  • p

    poohbar

    03/16/2018, 6:43 PM
    haha, mrkvicka 🥕
    😀 2
    l
    • 2
    • 1
  • p

    poohbar

    03/16/2018, 11:36 PM
    Second question, is there a way to differentiate between java class and kotlin class at runtime from within Java?
    a
    • 2
    • 1
  • p

    poohbar

    03/16/2018, 11:48 PM
    how do I find it at runtime?
    a
    • 2
    • 1
  • n

    nish

    03/17/2018, 5:05 PM
    This is just an arbitrary question, but why don’t long literals support lower case
    l
    ? because it looks like floats do with
    f
    .
    c
    n
    • 3
    • 3
  • c

    cedric

    03/17/2018, 6:16 PM
    Anyone here have a Kotlin project on github using Spek? Would love a link to it
    r
    • 2
    • 2
  • s

    Shakeib

    03/18/2018, 7:44 AM
    anyone please answer my question 😞
    a
    • 2
    • 3
  • c

    czuckie

    03/19/2018, 8:05 AM
    hi guys, I'm experiencing annoying issues that I'd love to report back to jb when using multiple instances of intellij on Mac OSX- is there any high verbosity settings for the IDE I should enable before gathering information? (It happens for kotlin projects as well as java, so it's semi related 😉 )
    d
    • 2
    • 2
  • k

    karelpeeters

    03/19/2018, 8:46 AM
    This is one of the downsides of slack, we've had the exact discussion before, it would have been better on stackoverflow.
    r
    • 2
    • 2
  • s

    spand

    03/19/2018, 10:20 AM
    In our project we are using hexagonal architecture with a domain module and many smaller modules that all depend on it (subproject setup in gradle). As the project has grown it seems compile times in IDEA (possibly also in gradle) slows to a crawl for 30 - 180 seconds as it seems to recompile the world constantly. Even for simple changes. Does anyone have any good approach that works better than what I have described ?
    s
    • 2
    • 2
  • r

    rrader

    03/19/2018, 10:33 AM
    Is there a way to disable not null checks? https://stackoverflow.com/questions/49360740/disable-not-null-checks-in-kotlin
    e
    • 2
    • 3
  • h

    hho

    03/19/2018, 10:36 AM
    @rrader You can add a
    ?
    after `String`… 😉
    r
    • 2
    • 1
  • a

    altavir

    03/19/2018, 10:37 AM
    If you want something that is not nullable but is assigned later, you can use
    lateinit var
    . Though I do not know.how it interacts with the framework.
    r
    e
    a
    • 4
    • 25
Powered by Linen
Title
a

altavir

03/19/2018, 10:37 AM
If you want something that is not nullable but is assigned later, you can use
lateinit var
. Though I do not know.how it interacts with the framework.
r

rrader

03/19/2018, 10:41 AM
the framework is calling constructor, so it passes the values, and after that it does the checks, so this will not help
a

altavir

03/19/2018, 10:43 AM
I don' really understand. Constructor is called twice?
r

rrader

03/19/2018, 10:45 AM
no, framework receive a json request, and should map json to class, so first it construct the object, and after that do validation, even not null validation
a

altavir

03/19/2018, 10:48 AM
OK, I seem to have not understood the problem. According to other answers, the problem is with annotations, not the nullability itself.
r

rrader

03/19/2018, 10:50 AM
We just need to not generate Intrinsics.checkParameterIsNotNull(name), just in this cases, not everywhere than everything will work
e

Evgeniy Zaharov

03/19/2018, 10:52 AM
@rrader you could disable intrinsics by startup parameter, but it’s not good decision, better to find another solution. Look at this answer: https://stackoverflow.com/a/42000389/5400641 (it’s possible to configure jackson to check that you want)
r

rrader

03/19/2018, 10:55 AM
yeap, I know, but we do not want fails on the first missing property
a

altavir

03/19/2018, 10:55 AM
I do not think it is a good solution, or solution at all. Null safety is one of the cornerstones of kotlin and one can't allow user just to turn it off.
r

rrader

03/19/2018, 10:56 AM
if we will be able to mark classes in order to not generate checks than this will be ok
@altavir we need this only in json mapping cases, so not everywhere
validation is done by framework, so null safety will not be affected
a

altavir

03/19/2018, 11:00 AM
If you allow it just once, then you can't ever be sure that null safe variable is really null safe.
r

rrader

03/19/2018, 11:01 AM
well, in Kotlin already exists
!!
, so yes, it will be our choise
a

Andreas Sinz

03/19/2018, 12:39 PM
use a different framework? :trollface:
on a more serious note, I think your framework is doing it the java way (which is obviously wrong). if you allow a
String
to be
null
, then you lose all of the compile-time guarantees. IMO it sounds like "Hey, lets fix the symptoms"
r

rrader

03/19/2018, 1:36 PM
yes I agree, but I can not change the framework, it is not so simple
a

Andreas Sinz

03/19/2018, 1:37 PM
instead of kotlin classes for your DTOs, maybe use Java classes
e

Evgeniy Zaharov

03/19/2018, 1:42 PM
as a not very good solution, you may try to create 2 dto objects with common interface, contains all properties, and on first one make all properties
nullable
, and on second choose as needed. With this you will only needed to add mapping from one dto object, to second. But it’s possible to do it with reflection (like ModelMapper library do)
r

rrader

03/19/2018, 1:57 PM
Why? Kotlin already have
-Xno-param-assertions
option, why not restrict this by annotation?
a

Andreas Sinz

03/19/2018, 2:07 PM
why waste precious time of the developers to fix the symptoms of java code?
i mean if its a very common problem, they tend to fix it (e.g.
lateinit
), but you can still create a yt-issue and see what the devs say
e

Evgeniy Zaharov

03/19/2018, 2:15 PM
-Xno-param-assertions
is a very bad solution, you will disable all runtime checks. So you will lose early failing on errors.
r

rrader

03/19/2018, 2:16 PM
yes, So I only want an annotation to be able to not disable all runtime checks 🙂
a

Andreas Sinz

03/19/2018, 2:46 PM
and still a null can lurk deep into your code when one part has no runtime checks 😉
r

rrader

03/19/2018, 3:15 PM
yeap, but this is checked by framework and tests 😉
View count: 3