KEEP icon indicating copy to clipboard operation
KEEP copied to clipboard

Add a proposal for "data objects"

Open strangepleasures opened this issue 3 years ago • 1 comments

strangepleasures avatar Aug 04 '22 17:08 strangepleasures

The @hash part is meaningless even for non-ADT objects, because object is a singleton

On JVM, a data object is a singleton in each ClassLoader, so multiple objects with the same FQN (and maybe the same code) can coexist in the same process. The hash part is useful to detect different instances of the "same singleton". This kind of issue occurs when multiple ClassLoaders are used, ie OSGi. I note that only for completeness, but I don't think that the Kotlin language should address this issue.

copy makes no sense because it’s a singleton. Or should it be generated and always return this?

the copy method should never return this

fvasco avatar Aug 05 '22 07:08 fvasco

The hash part is useful to detect different instances of the "same singleton".

Wouldn't it be more natural to use the === operator for that?

strangepleasures avatar Sep 08 '22 10:09 strangepleasures

    kotlinOptions {
        jvmTarget = '1.8'
        languageVersion = '1.9' // data objects
    }

kotlin.sourceSets.all {
    it.languageSettings.enableLanguageFeature("DataObjects")
}

Zhuinden avatar Jan 05 '23 10:01 Zhuinden