testcontainers-java: Problems with TestContainers and Kotlin
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.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 58
- Comments: 15 (4 by maintainers)
My workaround is:
And use it everywhere I’d need otherwise to use
GenericContainer. Charming, isn’t it ? 😃Another ugly way to handle this as described in the YouTrack issue:
@helmbold Chaining is easily possible with Kotlin native scoping functions, example:
I’ll make a merge request to propose this in the Kotlin Examples.
First time I tried to use Testcontainers with Kotlin and ran into exactly this problem, so great it found the workarounds here 😅
Just reading this generic expression gives you a headache 😃 On Sat, 1 Apr 2017 at 20:09 Richard North notifications@github.com wrote:
I created a sub class of MySQLContainer:
@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?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
This saved my life… Was to frustrated and I did not find this thread.
@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.
@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!
Please close this issue as Kotlin 1.6 which fixes it has been released.