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

    kevinherron

    07/30/2021, 9:55 PM
    Updating to 1.5 and having trouble with unsigned…
    Kotlin: Type of the constant expression cannot be resolved. Please make sure you have the required dependencies for unsigned types in the classpath
    wha?
    • 1
    • 1
  • z

    zain

    08/01/2021, 10:40 AM
    How to do multi switch cases like Swift in Kotlin using when?
    func getMode() -> Mode {
            var mode: Mode = .live
            switch (gdIsLocked, gdIsCurrent, matchIsLocked, matchIsCurrent) {
            case (0,1,0,1):
                mode = .manage
            case (1,1,1,1):
                mode = .live
            case (1,1,1,0):
                mode = .substitution
            case (1,2,1,2):
                mode = .points
            case (0,0,0,0):
                mode = .upcoming
            default:
                mode = .upcoming
            }
            return mode
        }
    
        enum Mode {
            case manage
            case substitution
            case live
            case points
            case upcoming
        }
    ❤️ 1
    n
    e
    • 3
    • 7
  • a

    Ayfri

    08/02/2021, 2:50 AM
    Hi, is there a specific channel for asking for help about Minecraft Modding in Kotlin ? ^^
    y
    c
    • 3
    • 3
  • t

    Tom Haywood

    08/02/2021, 5:17 AM
    Hi All. I'm in the process of migrating a service, written in a combination of Java 8 and Kotlin, to Java 16. I am seeing some bizarre behaviour that I can't find an explanation for. The code below ends up with notTheSame set to true, when someField has the value of 2, which is the same as the value of the constant it is being compared with. (someField is read from a database). The (obviously modified) code shows the comparison:
    fun isXXX(current: Foo, previous: Foo?): Boolean {
    	val notTheSame = previous?.someField != someConstant
    	if (notTheSame) {
    		println("${previous?.someField} != $someConstant")
    	}
    	...
    }
    The data class:
    data class Foo(
        ...
        var someField: Short = initial,
    	...
    )
    The constants:
    const val initial: Short = -1
    const val someConstant: Short = 2
    Could someone please help me understand the cause, or point me to where I should look? Code hasn't been touched for over a year, and I'm updating every single JAR used at the same time. Thanks.
    s
    • 2
    • 5
  • s

    Slackbot

    08/02/2021, 2:18 PM
    This message was deleted.
    b
    d
    • 3
    • 5
  • a

    anatawa12

    08/03/2021, 3:39 AM
    Is Kotlin 1.5.21 for Intellij 2021.2(.0) going to be released?
    k
    e
    +2
    • 5
    • 4
  • t

    TwoClocks

    08/03/2021, 5:25 PM
    it's seems like build in types (
    Int
    etc) copy on assignment, but classes create a reference on assignment. (see this simple example : https://pl.kotl.in/tTP-Co4SS). If I want to make my own numeric-ish type is there a way to behave the same as
    Int
    on assignment?
    m
    • 2
    • 13
  • a

    Alexis Manin

    08/03/2021, 5:43 PM
    Not sure, but maybe with inline class ? See this modified playground : https://pl.kotl.in/U09d9eWIB
    t
    • 2
    • 6
  • t

    TwoClocks

    08/03/2021, 11:21 PM
    I get compiler errors about smartcasting mutable vars because it might have changed. Is there a way to disable that? It can't have changed because it's a single threaded app, and I checked for null in the previous statement, like
    if( thing != null && thing.value > 10)
    I can't use
    thing?.value
    because of a known bug in 1.5.20...
    d
    s
    • 3
    • 4
  • d

    Damien

    08/03/2021, 11:43 PM
    A generics question, if this is the right channel. I think I have a legitimate use of an
    out
    parameter, but the compiler is complaining. Error: Type parameter T is declared as 'out' but occurs in 'in' position in type (T) -> C<T>
    Generics_Variance.cpp
    e
    • 2
    • 3
  • m

    Matthew Cachia

    08/04/2021, 9:14 AM
    A question about reified type parameters.
    inline fun <reified T> test(): Unit {
        println(T::class.java.typeParameters.joinToString(separator = ","))
        println(T::class)
    }
    
    fun main() {
        test<Either<ReferenceObject, SchemaObject>>()
    }
    Is there a way I can retain
    ReferenceObject
    ,
    SchemaObject
    ? It looks like reified is not recursive...
    r
    e
    • 3
    • 3
  • z

    zain

    08/04/2021, 4:16 PM
    How to get sum of all second element of a List<Pair<String, Int>>
    e
    f
    • 3
    • 3
  • t

    TwoClocks

    08/05/2021, 3:44 AM
    I wrote my own extension function for
    sumOf
    on
    Iterable
    for my own numeric-ish type. but I'm unsure on where to put it. If I put it in the file that calls
    sumeOf
    it works, but if I put my impl in the file where my type is (which is where I think it should live), the compiler can't find it. Is there some magic to tell the compiler where the impl is?
    r
    e
    • 3
    • 3
  • m

    Mohammad Jahidul Islam

    08/05/2021, 6:20 AM
    Any one please explain this code. Thanks
    r
    s
    • 3
    • 4
  • h

    haris mehmood

    08/05/2021, 10:43 AM
    {
        
    "responseCode": 200,
        
    "message": "Success",
        
    "response": {
            
    "Items": [
                
    {
                    
    "purpose": "Instant Checkup",
                    
    "date": "16 Jul 2021",
                    
    "created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
                    
    "uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
                    
    "amount": 1500,
                    
    "Version": "2012-10-17",
                    
    "Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f6"
                
    },
                
    {
                    
    "purpose": "Instant Checkup",
                    
    "date": "16 Jul 2021",
                    
    "created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
                    
    "uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
                    
    "amount": 1500,
                    
    "Version": "2012-10-17",
                    
    "Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f9"
                
    },
                
    {
                    
    "purpose": "Instant Checkup",
                    
    "date": "16 Jul 2021",
                    
    "created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
                    
    "uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
                    
    "amount": 1500,
                    
    "Version": "2012-10-17",
                    
    "Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f1"
                
    },
                
    {
                    
    "purpose": "Instant Checkup",
                    
    "date": "16 Jul 2021",
                    
    "created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
                    
    "uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
                    
    "amount": 1500,
                    
    "Version": "2012-10-17",
                    
    "Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f7"
                
    },
                
    {
                    
    "purpose": "Instant Checkup",
                    
    "date": "16 Jul 2021",
                    
    "created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
                    
    "uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
                    
    "amount": 1500,
                    
    "Version": "2012-10-17",
                    
    "Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f1511"
                
    },
                
    {
                    
    "purpose": "Instant Checkup",
                    
    "date": "16 Jul 2021",
                    
    "created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
                    
    "uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
                    
    "amount": 1500,
                    
    "Version": "2012-10-17",
                    
    "Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3"
                
    },
                
    {
                    
    "purpose": "Instant Checkup",
                    
    "date": "16 Jul 2021",
                    
    "created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
                    
    "uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
                    
    "amount": 1500,
                    
    "Version": "2012-10-17",
                    
    "Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f1510"
                
    },
                
    {
                    
    "purpose": "Promotion",
                    
    "date": "16 Jul 2021",
                    
    "created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
                    
    "uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
                    
    "Version": "2012-10-17",
                    
    "amount": 500,
                    
    "Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f5"
                
    },
                
    {
                    
    "purpose": "Instant Checkup",
                    
    "date": "16 Jul 2021",
                    
    "created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
                    
    "uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
                    
    "amount": 1500,
                    
    "Version": "2012-10-17",
                    
    "Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f2"
                
    },
                
    {
                    
    "purpose": "Appointment fee",
                    
    "date": "16 Jul 2021",
                    
    "created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
                    
    "uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
                    
    "Version": "2012-10-17",
                    
    "amount": 1000,
                    
    "Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f4"
                
    }
            
    ],
            
    "Count": 10,
            
    "ScannedCount": 10,
            
    "LastEvaluatedKey": "eyJJZCI6ICI0YWE3OTJkYS0yZWY4LTQyNTMtOGM3Yy0zZTNmNmI5ZjE1ZjQiLCAidXVpZCI6ICI0YWE3OTJkYS0yZWY4LTQyNTMtOGM3Yy0zZTNmNmI5ZjE1ZjMifQ=="
        
    }
    }
    Can we use this kind of response For paging library 3 ?
    🤦 2
    :goberserk: 3
    :not-kotlin: 6
    😒 5
    v
    • 2
    • 1
  • l

    louiscad

    08/05/2021, 10:57 AM
    @haris mehmood please, minimize long snippets, many of us are on mobile, walls of text like yours make checking the channel harder .
    ➕ 3
    :thread-please: 2
    n
    • 2
    • 1
  • s

    Slackbot

    08/05/2021, 2:09 PM
    This message was deleted.
    c
    v
    • 3
    • 5
  • j

    Jilles Soeters

    08/05/2021, 7:18 PM
    I have a
    List<String>
    with about 250 URLs. Currently I am doing a
    GET
    request to each url in a forEach loop so it’s synchronous. Obviously one of Kotlin’s amazing features is co-routines. Does anyone know of a good resource on how I could do this async? It’s currently taking 30 seconds while I feel like this could be done much much quicker async. Note I own all 250 URLs that are getting visited so I am not spamming anyone
    a
    c
    +3
    • 6
    • 16
  • f

    Florian

    08/06/2021, 10:34 AM
    When is it appropriate to use the
    !!
    operator? Example: In an edit and delete situation I never expect the
    todoId
    to be null, only when a new todo was added. Does it make sense to just use
    !!
    then instead of the null-safe operator?
    fun onAddEditResult(result: Int, todoId: Long? = null) {
            viewModelScope.launch {
                when (result) {
                    RESULT_TODO_ADDED -> eventChannel.send(Event.ShowTodoSavedConfirmationMessage("Todo added"))
                    RESULT_TODO_EDITED -> {
                        eventChannel.send(Event.ShowTodoSavedConfirmationMessage("Todo updated"))
                        setExpandedState(todoId!!, false)
                    }
                    RESULT_TODO_DELETED -> {
                        val todo = todoDao.getTodoById(todoId!!)
                        todo?.let {
                            todoDao.delete(todo)
                            setExpandedState(todo.id, false)
                            eventChannel.send(Event.ShowUndoDeleteTodoMessage(todo))
                        }
                    }
                }
            }
        }
    e
    y
    +2
    • 5
    • 30
  • s

    Scott Whitman

    08/06/2021, 12:46 PM
    How do you override the equals operator so that you can apply it to sibling classes? I always get Operator '==' cannot be applied to 'Length.Kilometer' and 'Length.Meter' in the below example. Kotlin Playground: https://pl.kotl.in/uT4Ch5mem
    abstract class Length {
        abstract val meters: Double
    
        override fun equals(other: Any?): Boolean {
            if (this === other) return true
            if (other !is Length) return false
            return meters.equals(other.meters)
        }
    
        override fun hashCode() = meters.hashCode()
    
        class Meter(value: Double) : Length() {
            override val meters: Double = value
        }
    
        class Kilometer(value: Double) : Length() {
            override val meters: Double = value * 1000.0
        }
    }
    
    fun main() {
        val oneKm = Length.Kilometer(1.0)
        val oneThousandMeters = Length.Meter(1000.0)
    
        println(oneKm.equals(oneThousandMeters))
        // true
    
        println(oneKm as Length == oneThousandMeters as Length)
        // true
    
        println(oneKm == oneThousandMeters)
        // this will not compile: Operator '==' cannot be applied to 'Length.Kilometer' and 'Length.Meter'
    }
    k
    h
    • 3
    • 3
  • a

    Ayfri

    08/06/2021, 3:57 PM
    Hi, why can't I use a vararg argument for a typealias of a function ?
    y
    t
    • 3
    • 3
  • m

    Mohammad Jahidul Islam

    08/07/2021, 9:47 AM
    Sealed class Item( val name: String) { object Item1: Item("Mango") object Item2: Item("Grapes") } How to add Item objects in a list with function? Sample: val items = listOf( Item.Item1, Item.Item2)
    g
    p
    • 3
    • 4
  • j

    Jasmine Dupré

    08/07/2021, 9:12 PM
    Hi, I am building a web app using kotlin. The team suggested using kotlin backend and angular front end but I’m not sure if kotlin integrates well with angular. Is that true? Also, if there is ktor to create a full stack kotlin web, why not use that? I’ve read a lot of pros of Kotlin in full stack but can’t seem to find any cons. Are there any? Thanks.
    t
    • 2
    • 8
  • s

    Sonu Sanjeev

    08/08/2021, 4:07 AM
    Hi, When I write code like this on a setter function, I am getting the following error Type mismatch. "*Required: Unit, Found: Boolean*".
    var isRectangle: Boolean
            get() = field
            set(value) = value.not()  // The error is here
    How is it possible to return a Unit type when we use a syntax like "set(value) = " . Thanks in Adavance
    e
    j
    • 3
    • 20
  • r

    Rafael Costa

    08/08/2021, 10:16 AM
    (I mean how can it (the singleton
    AmountScreen
    ) be null?)
    r
    m
    • 3
    • 6
  • a

    althaf

    08/08/2021, 5:39 PM
    hi is there better way to frame this code
    fun make(rows: Int, cols: Int): String {
        val table = StringBuilder()
        for (rpos in 0..rows) {
            table.append(START_ROW)
            for (cpos in 0..cols) {
                val cell = "${START_CELL}${cpos+rpos}${END_CELL}"
                table.append(cell)
            }
            table.append(END_ROW)
        }
        return table.toString()
    }
    d
    e
    • 3
    • 3
  • r

    Robert Jaros

    08/08/2021, 7:31 PM
    When developing gradle plugin in Kotlin, IntelliJ gives me such errors:
    Cannot access class '<http://java.io|java.io>.File'. Check your module classpath for missing or conflicting dependencies
    or
    Cannot access class 'java.util.concurrent.Callable'. Check your module classpath for missing or conflicting dependencies
    But there are no errors when building this project from Gradle command. Any ideas what can be wrong?
    t
    a
    • 3
    • 6
  • s

    smallufo

    08/08/2021, 8:35 PM
    How to auto apply init block after applying a functional block ? Take this code for example :
    class Config(var degree: Double = 315.0) {
      init {
        require(degree > 180 && degree < 360)
        { "degree should between 180 and 360" }
      }
    }
    And if we initialize
    Config
    directly , it will check the value as expected :
    @Test
    fun normalTest() {
      try {
        Config(90.0)
        fail()
      } catch (e: Exception) {
        assertTrue(true)
      }
    }
    But if there is a function accepting the
    Config
    as functional object :
    private fun calculate(block: Config.() -> Unit = {}) {
      val cfg = Config().apply(block)
      println("do something... with degree = ${cfg.degree}")
    }
    
    @Test
    fun testCalculate() {
      try {
        calculate {
          degree = 90.0
        }
        fail("It SHOULD fail")
      } catch (e: Exception) {
        assertTrue(true)
      }
    }
    It will skip the
    init
    check block . How to solve this problem ? Thanks. I could only think of this solution :
    class Config(var degree: Double = 315.0) {
      init {
        check()
      }
    
      fun check() {
        require(degree > 180 && degree < 360)
        { "degree should between 180 and 360" }
      }
    }
    and …
    private fun calculate(block: Config.() -> Unit = {}) {
      val cfg = Config().apply(block).also { it.check() }
      println("do something... with degree = ${cfg.degree}")
    }
    But I think it is so ugly … Is there any better way ? Thanks.
    a
    r
    e
    • 4
    • 14
  • a

    andyg

    08/08/2021, 11:15 PM
    Hi I have been trying to use the MANIFEST.MF file to hold on to some basic metadata info such as the build version... following some Stack Overflow responses which use methods like
    MyApplication::class.java.`package`.implementationVersion
    or
    Thread.currentThread().contextClassLoader.getResources(JarFile.MANIFEST_NAME)
    but they all result in a NULL. I looked deeper, IntelliJ doesn't even create a MANIFEST.MF when Running/Debugging (although it does when `gradle build`'ing a JAR file). Any tips on what I'm doing wrong? (this is NOT an Android project)
    b
    • 2
    • 4
  • y

    y9san9

    08/09/2021, 5:17 AM
    Hello mates, why there is such a restriction on named params? I mean, ofcourse Java cannot have named params, but I'm used to put param names for kinda not obvious consts, so I can view the file without IDE and see what this values mean. It may be useful if I could 'name' the param but keep its position, so after compilation param names will be just erased. UPD: Preventing misunderstand: • compiler should check that the order and names are correct • in runtime actually arg names should be erased
    r
    f
    • 3
    • 12
Powered by Linen
Title
y

y9san9

08/09/2021, 5:17 AM
Hello mates, why there is such a restriction on named params? I mean, ofcourse Java cannot have named params, but I'm used to put param names for kinda not obvious consts, so I can view the file without IDE and see what this values mean. It may be useful if I could 'name' the param but keep its position, so after compilation param names will be just erased. UPD: Preventing misunderstand: • compiler should check that the order and names are correct • in runtime actually arg names should be erased
r

Rob Elliot

08/09/2021, 7:13 AM
If the Java method took two String arguments then it could be deeply misleading - you could swap the order of the arguments in the call (or in the declaration if it was local) and it would all still compile with the wrong names.
Named arguments implies that the compiler is checking something for you when it isn’t.
y

y9san9

08/09/2021, 7:15 AM
Please read again my message, compiler should check that the order is correct. I saw this behaviour before, when after named arguments there are positional one, compiler requires correct positioning even for named args 🙂
For example, there is already order control
As I see, this was done exactly for cases when you want to directly tag const arguments
f

Fleshgrinder

08/09/2021, 9:08 AM
The problem would be if Java adds support for named arguments as it could require breaking the existing implementation. This would be bad for all if it would be the case. Have you considered comments? This way you could achieve what you want.
y

y9san9

08/09/2021, 9:54 AM
Yes, now I do this with comments I don't think Java can do such syntax that won't allow named arguments placed positionally, it could be just a dumb implementation, there is no way it will be
r

Rob Elliot

08/09/2021, 10:20 AM
I’ve read it several times and I still don’t really understand what you want to be able to do but cannot do. Is it that you want to call methods from a lib not compiled with kotlinc using named params? Or that you want to mixed named and unnamed params?
y

y9san9

08/09/2021, 10:34 AM
I want to do stuff that I've shown on screenshot in topicstart, but without comments
Named comments in Java, but keeping positions, so it will be just a pointer in sources
r

Rob Elliot

08/09/2021, 10:54 AM
The Java specification makes it optional whether parameter names are included as metadata when javac compiles a class, and by default they are not. So kotlinc can’t rely on them being there. And just because they are there in version 1.0.0 of a module doesn’t mean they will be there, or be the same, in version 1.0.1; most Java devs wouldn’t consider parameter names part of the binary compatibility of their lib (though as they are reachable by reflection if present they arguably should…).
y

y9san9

08/09/2021, 10:59 AM
That's a point, thanks!
View count: 3