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

Provide an implicit for AutoCloseable instead of Closeable #80

Merged
merged 1 commit into from
Aug 20, 2019

Conversation

adampauls
Copy link
Contributor

@adampauls adampauls commented Aug 18, 2019

Right now, Resources can be implicitly derived AutoCloseables, but (surprisingly) only through reflection, which incurs an enormous performance penalty. I'm not really sure why -- java.lang.AutoCloseable is the prescribed interface for ARM in java and has been for quite some time. I'm guessing there is some reason for keeping things this way since this change is so trivial, but I thought I'd put it up to start discussion.

Fixes #66.

Thanks!

@adampauls adampauls changed the title Provide implicits for AutoCloseable instead of Closeable Provide an implicit for AutoCloseable instead of Closeable Aug 18, 2019
@@ -44,4 +44,4 @@ Type classes in scala are encoded using implicit parameters. Due to the mechan

These two implicits allow users of the library to make use of any resource class that defines a close or dispose method. The downside is that by using structural types, the close and dispose method will be invoked via reflection.

The scala-arm library also provides default implicits for common resources used from the Scala library or the Java SDK. In particular, anything that extends `java.io.Closeable` will *not* use reflection when closing the resource. This type class is given slightly higher priority so it will be preferred to the reflective version when resolving implicits.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, that would be a breaking change to right the stronger AutoCloseable to be required

Copy link
Contributor Author

@adampauls adampauls Aug 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AutoCloseable is weaker though? All Closeables are AutoCloseables?

@cchantep
Copy link
Collaborator

Right I always find the JSE naming misleading about that.

@adampauls
Copy link
Contributor Author

What is the etiquette here? Should I merge now or let one of the maintainers do the honors?

@adampauls
Copy link
Contributor Author

(And thanks for the quick approval!)

@cchantep
Copy link
Collaborator

Can merge once approved and passing CI

@adampauls
Copy link
Contributor Author

Oh I see, I can't merge anyways. I'll let one of you do it, thanks again!

@cchantep cchantep merged commit cd80674 into jsuereth:master Aug 20, 2019
@adampauls adampauls mentioned this pull request Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No implicit for AutoCloseable
2 participants