Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with TestContainers and Kotlin #318

Closed
iirekm opened this issue Mar 31, 2017 · 14 comments
Closed

Problems with TestContainers and Kotlin #318

iirekm opened this issue Mar 31, 2017 · 14 comments

Comments

@iirekm
Copy link

iirekm commented Mar 31, 2017

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.

@martin-g
Copy link

martin-g commented Mar 31, 2017

My workaround is:

class KGenericContainer(imageName: String) : GenericContainer<KGenericContainer>(imageName)

And use it everywhere I'd need otherwise to use GenericContainer.
Charming, isn't it ? :-)

@rnorth
Copy link
Member

rnorth commented 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
Copy link
Contributor

asafm commented Apr 1, 2017 via email

@mpecan
Copy link

mpecan commented Jul 18, 2017

This is related directly to #238 and can be resolved in the way that was suggested by @bsideup (#238 (comment)).

@mkobit
Copy link

mkobit commented May 16, 2018

Another ugly way to handle this as described in the YouTrack issue:

val container: GenericContainer<*> = GenericContainer<Nothing>()

@helmbold
Copy link

@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
Copy link
Member

kiview commented 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
Copy link

@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.

@xyzwps
Copy link

xyzwps commented Oct 29, 2019

I created a sub class of MySQLContainer:

internal class SpecifiedMySQLContainer(val image: String) : MySQLContainer<SpecifiedMySQLContainer>(image)

val mysqlContainer = SpecifiedMySQLContainer(image = "mysql:5.7.28").withDatabaseName("dbname")

@thaibt
Copy link

thaibt commented Apr 23, 2021

Another ugly way to handle this as described in the YouTrack issue:

val container: GenericContainer<*> = GenericContainer<Nothing>()

This saved my life... Was to frustrated and I did not find this thread.

@schnapster
Copy link

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
Copy link

Please close this issue as Kotlin 1.6 which fixes it has been released.

@bsideup
Copy link
Member

bsideup commented 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!

@bsideup bsideup closed this as completed Dec 28, 2021
@sdeleuze
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests