https://kotlinlang.org logo
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
benchmarks
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
confetti
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
lincheck
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
Title
b

basher

02/10/2019, 5:37 PM
Is there a roadmap or plans for Kotlin to improve generics (breaking with Java)?
c

Czar

02/10/2019, 5:41 PM
There is no simple answer for such a broad question. You could look at the issue tracker and if you can't find your specific problem, file an issue for it.
b

basher

02/10/2019, 5:52 PM
I do have specific generics features I’d like to see, but it seems like with reified types, there is some sense that there might be future plans to build more generics improvements. Maybe there is a KEEP or something like that?
n

nfrankel

02/10/2019, 6:56 PM
reified generics are in the java roadmap because that is definitely a bytecode breaking change it will be much easier to wait for that to happen and only then implement it in kotlin
b

basher

02/10/2019, 7:06 PM
Ah so more reified generics coming then?
Do you know where I can find that roadmap by chance?
l

louiscad

02/10/2019, 7:18 PM
Kotlin 2.0 or later, if they ever do it. Reified generics is something that was experimented before Kotlin 1.0 but was dropped for performance reasons on the JVM.
beware, it’s an option
b

basher

02/10/2019, 7:55 PM
Thanks!
👍 1
g

gildor

02/11/2019, 5:15 AM
@basher Just curious, what is your use case for reified generics that not covered by reified inline or upcoming
typeOf
operator?
As I understand the goal of Valhalla about generics is not real reified generics support, but specialised generics for primitive types, this is not exactly the same and will work only for generics for primitives and for classes that explicitly support it
👆 1
👍 2
b

basher

02/12/2019, 12:26 AM
@gildor i'm not familiar with
typeOf
actually. i'm looking to be able to call a constructor on a generic type that's constrained to inherit from an abstract class that requires that constructor
g

gildor

02/12/2019, 12:33 AM
@basher wouldn't be more clear and flexible solution provide factory for the type? Because reified generics is huge thing that also doesn't solve all the cases (like what if you have interface, not an abstract class)
Also, there is related discussion about reified generics, especially check article about reified vs erased generics in second message of this thread https://kotlinlang.slack.com/archives/C0B9K7EP2/p1549657528197100?thread_ts=1549657528.197100&cid=C0B9K7EP2
b

basher

02/12/2019, 5:53 PM
wouldn't be more clear and flexible solution provide factory for the type?
Being frank: coming from another language where it's common to have static requirements on generic abstract types and interfaces, factories feel like a crutch. You instantiate them once, so that you can use their instance methods like static methods
g

gildor

02/13/2019, 12:49 AM
But isn't it break encapsulation and make code less flexible? Also, how can you instantiate interface?
Also if you have instance of some interface/class, maybe better add factory to interface, so it would be encoded to types
b

basher

02/13/2019, 4:58 PM
As a side-effect, factories do make you think about how you want to break up your code, but this feels like overkill for something simple (see contrived example below).
Also, how can you instantiate interface?
fun <T: SomeInterface> makeOne(): T {
    return T()
}
If interfaces allowed static requirements, like constructors, you could do something like that ^
g

gildor

02/13/2019, 5:10 PM
But there is no proof (from type system) that such class has default constructor, so what should happen, crash on runtime? Looks too dynamic and unsafe for me. Also with inline function + reflections you can do this even now
inline fun <reified T: SomeInterface> makeOne(): T {
    return T::class.java.newInstance()
}
b

basher

02/13/2019, 5:13 PM
Right that's the state today. I'm trying to make the case for
constructor
defs in `interface`s
g

gildor

02/13/2019, 5:14 PM
But there is no such thing as constructor in interface
b

basher

02/13/2019, 5:15 PM
I'm wishing there was 🙂
I started this discussion asking about the roadmap for generics, hoping that something like this would be on it 🙂
g

gildor

02/13/2019, 5:15 PM
But why? Isn't factory solves this in a more flexible way?
b

basher

02/13/2019, 5:17 PM
It solves it, and it's still a tool that you can use in both worlds. But that requires a non-trivial amount of extra code, compared to (for these kinds of small cases):
fun <T: SomeInterface> makeOne(): T {
    return T()
}
g

gildor

02/13/2019, 5:18 PM
Also, what is you real use case, because this is probably a part of some more complex feature where you need this
b

basher

02/13/2019, 5:19 PM
We implemented a generic sync system in Swift, which relies heavily on static requirements in interfaces (protocols in Swift). I've found that as I try to write the same thing in Kotlin, I spend a lot of time writing factories to work around this constraint
g

gildor

02/13/2019, 5:20 PM
This doesn't look for me as non-trivial amount of code
fun <T : SomeInterface> makeOne(factory: () -> T): T {
   return factory()
}
Also you get flexibility and compile time safety
In a simple case usage is also pretty concise: makeOne(::SomeImpl)
b

basher

02/13/2019, 5:24 PM
That's true. I agree it's not very hard to write a factory. But coming from a language without them. That contrived example is simpler without them though (no indireection through the lambda). In Swift, you still get compile time safety because the interface/protocol has the constructor requirement, so the compiler knows what you're calling.
g

gildor

02/13/2019, 5:24 PM
I want to be clear, that there are valid use cases for reified generics for sure, but this is so huge feature with a lot problems that I just not sure that such use cases is really worth it
Isn't constructor in interfaces doesn't require reified generics and may work itself?
And reified generics without constructor doesn't give you compile type safety
b

basher

02/13/2019, 5:27 PM
I don't think I'll be able to convince you that it's worth it. All I can say is that I've found I've been able to write concise code with it without factories, which I think was nice.
Also reified generics without constructor doesn't give you compile type safety
I don't know enough about Kotlin/Java to refute that yet. Swift is able to do this with compile-time safety though somehow, but they're different languages with different constraints. 🤷‍♂️
g

gildor

02/13/2019, 5:29 PM
No need to convince me, I really curious about use cases. There is a lot of nice features, but each language feature has a price and price of reified generics is pretty high imo
b

basher

02/13/2019, 5:29 PM
What is the price exactly?
g

gildor

02/13/2019, 5:30 PM
Performance, language complexity, interopability with other platform languages (java, js, C), maintenance cost
🤷‍♂️ 1
And any kinds of problems with feature itself (how it works with other language features for example)
b

basher

02/13/2019, 5:32 PM
TBH, those feel like arguments to not build any new language features
g

gildor

02/13/2019, 5:33 PM
Yes, sure, it is, but it's valid argument, otherwise you will get Scala or C++
b

basher

02/13/2019, 5:34 PM
Those are both pretty popular, well-liked languages
g

gildor

02/13/2019, 5:35 PM
And very complex with own problems that harm them a lot
b

basher

02/13/2019, 5:35 PM
Doesn't mean Kotlin needs to converge to be like those, but it's certainly an opportunity to become something great, which means making useful features
g

gildor

02/13/2019, 5:37 PM
"Interesting" feature is probably not really a goal of Kotlin, as I understand it
b

basher

02/13/2019, 5:37 PM
Updated 🙂
g

gildor

02/13/2019, 5:39 PM
Yes, "useful" definitely make sense, also "practical"
It's more philosophical thing, instead I would really like to discuss use cases and examples of real code where it would be helpful and discuss problems that it may cause
b

basher

02/13/2019, 5:43 PM
I presented one that is both practical and well used in our codebase (also well-used in the Swift language/stdlib), and you responded with "here's the Java pattern that solves it." It doesn't seem like you're open to that discussion, if there's already a code pattern that solves the use case. With that same argument, you don't need generics either
g

gildor

02/13/2019, 5:44 PM
This is not "the java pattern", it's universal pattern that also may be used even with reified generics and interface constructors if you need more flexible solution
If you have a hammer everything looks as a nail, so if some feature used a lot in one language it doesn't mean that you don't have alternatives in another language
Like macroses used a lot in languages where they exist, but it doesn't mean that it good feature just because of that
b

basher

02/13/2019, 5:47 PM
So now it doesn't matter what use cases I present?
g

gildor

02/13/2019, 5:56 PM
Why do you think so? I just pointed that reified generics itself cannot solve proposed use case in a safe way and that existing alternatives are not so bad, that's all, this is just my opinion, sorry if something in my messages looked rude for you
c

Czar

02/13/2019, 5:57 PM
Sounds like a nifty feature, which has many drawbacks within Kotlin ideology (pragmatic language with near-100% near-seamless Java interop). If you think that its pros outweigh cons, I'd suggest writing a KEEP, maybe it will catch on. This discussion doesn't seem very productive at this point 🙂
b

basher

02/13/2019, 5:59 PM
@Czar good point i'll consider that thanks! anything you can point me to about how to write one (tips or just a well-written one)?
g

gildor

02/13/2019, 5:59 PM
Check Kotlin KEEP repo Readme and other proposals in PR section
c

Czar

02/13/2019, 6:04 PM
_ _👆
b

basher

02/13/2019, 6:06 PM
thanks!