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

Allow extension of Neo4jContainer class #1195

Merged
merged 1 commit into from
Jan 31, 2019

Conversation

portovep
Copy link
Contributor

@portovep portovep commented Jan 31, 2019

My team is trying to use Neo4jContainer in a Kotlin codebase but we have an issue with type inference.
Seems like Kotlin cannot infer the type when creating an instance of Neo4jContainer. The following code causes a type inference error:

val myNeo4jContainer = Neo4jContainer("imageName")

To fix it, a custom class that extends from Neo4jContainer needs
to be declared, for example:

class KNeo4jContainer(imageName: String) : Neo4jContainer<KNeo4jContainer>(imageName)

val myNeo4jContainer = KNeo4jContainer("imageName")

This change enables extending the Neo4jContainer class.

This will fix interop with Kotlin. Kotlin cannot infer type when creating an instance of Neo4jContainer. A custom class that extends from Neo4jContainer needs
to be declared, for example:

class KNeo4jContainer(imageName: String) : Neo4jContainer<KNeo4jContainer>(imageName)
@rnorth
Copy link
Member

rnorth commented Jan 31, 2019

Hi @portovep

Thanks for the PR. I'd say we're absolutely fine to remove the final keyword - that's no problem.

FYI we are considering other changes to our APIs to eliminate the self-typing and make things more Kotlin friendly in general. There's a very difficult balance to strike between usability, extends-ability and the fluent setter model. Unfortunately what looked like the least worst option a couple of years ago isn't the best thing for use with Kotlin now.

Thanks for the contribution!
Richard

@rnorth rnorth merged commit 1672e7c into testcontainers:master Jan 31, 2019
@bsideup bsideup added this to the next milestone Jan 31, 2019
@rnorth rnorth removed this from the next milestone Mar 12, 2019
@rnorth
Copy link
Member

rnorth commented Mar 12, 2019

@michael-simons
Copy link
Contributor

Interesting, so type inference doesn't work with final java classes? Good to know! Thanks!

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

Successfully merging this pull request may close these issues.

None yet

4 participants