Beyond average: 10 best practices for coding Java APIs

See the original posting on JavaWorld

Published around this time last year, jOOQ creator Lukas Eder‘s Java programming best practices are written as a series of caveats to the standard wisdom of API design. Eder writes: “Being an internal DSL, jOOQ challenges Java compilers and generics to the max, combining generics, varargs and overloading in a way that Josh Bloch probably wouldnÂ’t recommend for the ‘average API.'”

Digging into the “beast” that is Java, Eder emerges with some perennial best practices — “It often makes sense to free memory in the inverse order of allocation”; “Avoid returning anonymous, local or inner class instances from methods to the outside scope”; “Arrays or Collections should never be null” — and a handful related to new features in Java 8 (see his comments on using defender methods, Optional, and single abstract methods). More controversially, Eder takes on the question of whether it’s ever safe to make methods final by default:

To read this article in full or to leave a comment, please click here