Skip to content

Instantly share code, notes, and snippets.

View rzwitserloot's full-sized avatar

Reinier Zwitserloot rzwitserloot

View GitHub Profile

A response to Lucas Eder's "JDBC improvements and convenience method suggestions" post.

Before tackling each point individually, the theme of them all is 'make JDBC easier for end users', and I'm not so sure this is worthwhile, both design-wise and pragmatically.

JDBC is what it is. It contains a bunch of dubious design choices that cannot be revisited without breaking backwards compatibility for callers (JDBC as an interface has given itself a free pass to break compat for implementers).

The problem with shipping really nice APIs for moving targets in the core, is that the core is generally not the place to start adding dueling implementations, is not the place for code that may want to (lightly) break backwards compatibility, and it is not the place for implementations that trade expressive power away in favour of being nicer. Core libraries have to expose everything as much as possible, even things that almost nobody needs.

> Java+Lombok code is NOT valid Java code. Bottom line is if you remove Lombok annotations from the source code, the code will not only be not compilable but it will also be completely invalid Java. Java compiler will complain big time.
lombok ships with a delombok tool, which will convert your source code. If the concern is 'that means folks without lombok cannot write the source code', you can use that argument against upgrading java versions too which seems.. ill advised. If it's more about 'that means we can never ditch lombok' - that's not true.
> It is impossible to step-in and debug code, because the actual source code is not there.
The source code lombok generates doesn't have bugs. You can't step into a synthetic method generated by java itself either. (for example, if you have a private method, and an inner class calls that private method, java generates a package-private synthetic bridger. You cannot step into this). It's upside: You can't step into irrelevant things. You then use a setter as e
<project name="findjvmtest" default="findjvm.jdk8">
<target name="-findjvms.base">
<property file="jvms.properties" />
<available property="tools.exec.javahome" value="/usr/libexec/java_home" file="/usr/libexec/java_home" />
<condition property="tools.exec.reg" value="reg.exe">
<os family="windows" />
</condition>
</target>
<target name="-findjvm.jdk8.mac" unless="jvm.8.loc" if="tools.exec.javahome">
long cost = 0;
for (var option : promotionOptionList) {
long q = option.getQuantity();
long c = promotionRefOptionService.get(option.getOptionId()).getCreditCost();
cost += q * c;
}
@FunctionalInterface interface BetterRunnable<E extends Throwable> {
void run() throws E;
}
public class BetterLambdaThrow {
static <E extends Throwable> void runTwice(BetterRunnable<E> r) throws E {
r.run();
r.run();
}
import java.util.*;
class Test {
public static void main(String[] args) {
thisIsFine(5);
Arrays.asList(5).stream().map(Integer::toString);
}
static void thisIsFine(int x) {}
static void thisIsFine(Integer x) {}
public class JavacBrokenError {
public static void main(String[] args) {
test(5.0);
}
void test(double d) {}
void test(Double d) {}
}
org.jetbrains.annotations.NotNull
org.jetbrains.annotations.Nullable
org.checkerframework.checker.nullness.qual.NonNull
org.checkerframework.checker.nullness.qual.Nullable
edu.umd.cs.findbugs.annotations.NonNull
edu.umd.cs.findbugs.annotations.Nullable
org.netbeans.api.annotations.common.NonNull
public abstract class Command {}
public final class ExitCommand extends Command {}
public final class SayHelloCommand extends Command {}
@FunctionalInterface public interface CmdHandler<C extends Command> {
void onCommand(C command); // should probably have 'throws Exception' on it; most entrypoints do.
}
class Test {
void foo() {
class Bar extends Baz {
Bar retSelf() {
return this;
}
}
}
}