You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TestContainers depends on construction of raw types and pattern like class C<SELF extends C<SELF>>. Unfortunately Kotlin, and probably other JVM languages don't like it - see https://youtrack.jetbrains.com/issue/KT-17186
Adding static factory methods could solve those problems.
Reacted by Inaiat Henrique, Geoffroy Warin, Andrea Arcuri, Philipp Hauer, Sergei Peretiatko, Nikita Salnikov-Tarnovski, İlkin Balkanay, Maciej Kwidziński, Mike Kobit, Christian Helmbold and 48 more
And use it everywhere I'd need otherwise to use GenericContainer.
Charming, isn't it ? :-)
Reacted by Inaiat Henrique, Anders, Arnab Mitra, Nikolay Kuznetsov, Nikita Salnikov-Tarnovski, Todd Ginsberg, Christian Helmbold, Mikael Gueck, Marcos García, Will Lokes and 76 more
Reacted by Viacheslav Blinov, Mario Kapusta, rhoehmann, Even Lislebø, obvionaoe, João Freitas, Bohdan and QUSHLEE
Reacted by Philipp Hauer, Pete Cornish, Arnab Mitra, Justin Tormey, Sämir Hamadi, Tjeu Kayim, Jim Moore, Sean Hodges, Xavier Arias Seguí, Viacheslav Blinov and 8 more
Reacted by Tjeu Kayim, Xavier Arias Seguí, Christian Dräger, Viacheslav Blinov, Mike Emery, Leon Felipe Cordero, Dmitriy Varygin, João Freitas, Nicole Penn, Bohdan and 6 more
Reacted by Nikolay Kuznetsov, Christian Helmbold, Mikael Gueck, Maxim Pavlov, Daniel Leicht, Florian Hintermeier, Achraf, Hunter Sherman, vach, Tom Hermann and 4 more
Another ugly way to handle this as described in the YouTrack issue:
val container:GenericContainer<*> =GenericContainer<Nothing>()
Reacted by Viktor Isaev, Dan McCabe, Boon at Shift, Joonhyeok Im, Vitaly Chirkov, Viacheslav Blinov, mstrdev, Andreas Berger, Martin Vysny, Bruno Bottazzini and 9 more
First time I tried to use Testcontainers with Kotlin and ran into exactly this problem, so great it found the workarounds here 😅
Reacted by Joel Handwell, Luis Miguel Mejía Suárez, Artem Yakshin, Michel Krämer, Cody Moore, Jim Moore, Dan McCabe, James Millner, Vitaly Chirkov, Maxim Pavlov and 8 more
@helmbold Chaining is easily possible with Kotlin native scoping functions, example:
val container:GenericContainer<*> =GenericContainer<Nothing>()
.apply{ withExposedPorts(6379) }
I'll make a merge request to propose this in the Kotlin Examples.
Reacted by Richard North, Babur, Maksim Kostromin, Luca Piccinelli, Andrea Arcuri, João Freitas, Suresh, Sunny Pelletier, ser0l, Alex Sherwin and 9 more
internalclassSpecifiedMySQLContainer(valimage:String) : MySQLContainer<SpecifiedMySQLContainer>(image)
val mysqlContainer =SpecifiedMySQLContainer(image ="mysql:5.7.28").withDatabaseName("dbname")
Reacted by Josh Rotenberg, Keegan Witt, Thomas Deville-Duc, Sam, Broc Seib, Bengt Brodersen, Steve Smith, Russell J.B., Luiz Aguiar, Daniel André da Silva and 2 more
Reacted by Russell J.B., Daniel André da Silva and dzikoysk
@sdeleuze good point!
It is great to see Kotlin supporting more and more "in the wild" cases 🎉
IIRC some Spring's builders also benefited from it? Double win!
Yep indeed that fixed a few Spring builder APIs as well. I am glad the Kotlin team has listened feedback from the community to fix this really annoying issue.
@asomov I just tried val container: GenericContainer<*> = GenericContainer("someImage") with Kotlin 2.1.10 and it seems to work as expected. If you manage to reproduce, could you please share a repro?
Reacted by Eddú Meléndez Gonzales, Suresh and Andrey Somov
Activity
martin-g commentedon Mar 31, 2017
My workaround is:
And use it everywhere I'd need otherwise to use
GenericContainer.Charming, isn't it ? :-)
rnorth commentedon Apr 1, 2017
Yeah, I'd not appreciated this would be a problem with Kotlin but it's unfortunate :(
@bsideup, something to consider for the next version...
asafm commentedon Apr 1, 2017
mpecan commentedon Jul 18, 2017
This is related directly to #238 and can be resolved in the way that was suggested by @bsideup (#238 (comment)).
mkobit commentedon May 16, 2018
Another ugly way to handle this as described in the YouTrack issue:
helmbold commentedon May 29, 2018
@mkobit Method chaining as shown in the docs is not possible with your approach (
GenericContainer<Nothing>()).I suggest to use the workaround from @martin-g instead.
kiview commentedon Oct 11, 2018
First time I tried to use Testcontainers with Kotlin and ran into exactly this problem, so great it found the workarounds here 😅
alex0ptr commentedon Oct 10, 2019
@helmbold Chaining is easily possible with Kotlin native scoping functions, example:
I'll make a merge request to propose this in the Kotlin Examples.
xyzwps commentedon Oct 29, 2019
I created a sub class of MySQLContainer:
thaibt commentedon Apr 23, 2021
This saved my life... Was to frustrated and I did not find this thread.
schnapster commentedon Oct 22, 2021
Looks like Kotlin 1.5.30 ships with a preview for 1.6 that fixes this: https://kotlinlang.org/docs/whatsnew1530.html#improvements-to-type-inference-for-recursive-generic-types
sdeleuze commentedon Dec 28, 2021
Please close this issue as Kotlin 1.6 which fixes it has been released.
bsideup commentedon Dec 28, 2021
@sdeleuze good point!
It is great to see Kotlin supporting more and more "in the wild" cases 🎉
IIRC some Spring's builders also benefited from it? Double win!
sdeleuze commentedon Dec 28, 2021
Yep indeed that fixed a few Spring builder APIs as well. I am glad the Kotlin team has listened feedback from the community to fix this really annoying issue.
sdeleuze commentedon Mar 12, 2025
@asomov I just tried
val container: GenericContainer<*> = GenericContainer("someImage")with Kotlin2.1.10and it seems to work as expected. If you manage to reproduce, could you please share a repro?