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
Add lambda-friendly callback interfaces #156
Add lambda-friendly callback interfaces #156
Conversation
I am generally a fan of this, let me look at the details! |
Adding methods to IDBI and TransactionConsumer break compatibility with other implementations of them. I suspect no one has ever implemented TransactionHandler outside the core, but I caught grief for changing IDBI in the past. I am willing, but want to poll the mailing list before doing it. @christophercurrie can you ping the mailing list for feelings on adding to IDBI before we make a decision? |
IMO this is a positive change; I want to make sure it merges cleanly and makes sense in the context of the ever-looming Java 8 JDBI3. I can take a closer look at that aspect in a few days. I suspect the answer is that there are no issues and we will effectively revert this change, it will then be a source-level incompatibility to change to e.g. I also think the concept of |
Bump? |
I'll merge this shortly if there are no objections. |
Add lambda-friendly callback interfaces
Thanks! |
Do you want a release? |
Yes On Tue, Jul 14, 2015 at 1:06 PM, Steven Schlansker <notifications@github.com
|
@brianm Maven no longer supports Java 6. So I cannot build JDBI anymore :(
When will you give up on JDK6? :P |
This can be worked around with stupid bootclasspath tricks. I can create a new PR for that if it would help :/ |
That has been in place for a long time. Install a JDK6, set an environment variable "JDK6_HOME" to point at that installation ( As the travis build does. |
If someone finds time, you can dig into the toolchains (https://maven.apache.org/guides/mini/guide-using-toolchains.html) which should make this painless (and the error messages a bit less obscure). I may do that when I am back from Europe (early August). |
Released 2.63 |
Great! |
I just updated to 2.63 to get this change, and I'm getting compilation errors saying: Error:(101, 19) java: reference to withHandle is ambiguous I can fix it by adding a cast that indicates the first method is what I want, but this did end up being backwards incompatible. And it made my Java8 code messier by adding casts. This only appeared to be necessary when I had code that was in the form of:
If the lambda was in the form of
then the compiler correctly inferred the SAM that has a return value |
What was the actual code that triggers the error? |
|
Actually, that's an interesting point. @christophercurrie why did you introduce HandleConsumer when there is already HandleCallback, which seems to be OK as a FunctionalInterface? Just to remove the return type? |
I can see why a consumer interface is handy, but we should have a different -Brian On Tue, Jul 21, 2015 at 10:04 AM, Steven Schlansker <
|
Sorry this ended up not working transparently; I made a mistake of only testing with block lambdas rather than single statement lambdas. @stevenschlansker Yes, the point was simply to remove the need for spurious |
Is there a quick / good fix that doesn't involve reverting the change? Or should we back off and reconsider? |
rename |
@osi is correct. If you want to revert first to get a valid build out quickly, that seems reasonable. |
FWIW, it looks like there have been bugs in the JVM in this space, so I'd be curious which specific update of Java 8 that @osi is using. That said, I just updated from 1.8.0_31 to 1.8.0_51, and it creates a different problem that expresses itself in the same way. The solution in this case is to specify the parameter type.
With the parameter type in place, the lambda can be changed from void to returning, and Java 8 doesn't have a problem figuring out which one you want. Sadly, though, as-is this change still breaks code that worked before the change. I can do the legwork to prep the revert and/or the replacement if desired. |
If you can get the replacement ready today, I guess that's preferable to a revert? I can cut a release. |
Even more frustratingly, adding braces without a parameter type makes the compiler happy:
I get really tweaked when simple, apparently unnecessary changes to user code cause compiler issues. I was hoping that simply updating the compiler version would make the problem go away, but no such luck. Yes, I can get a PR to fix the issue today. |
I'm using 1.8.0_45. I fixed my code by adding a cast before the lambda to HandleCallback so the compiler knows which variant I meant. |
Released as 2.63.1 |
Using JDBI with Java 8 lambdas is great until you want a callback that doesn't return a value. You can't cast the lambda to
VoidHandleCallback
because lambdas can only be cast to interfaces. It's an annoyance, not an obstacle, but one that's bugged me often enough that I want a better experience, and it's pretty easy to add.This change adds functional interfaces that Java 8 can infer when the lambda does not return. It does not add any Java 8 dependencies.
Objections?