logo

Quotes from Joshua Bloch

Learning the art of programming, like most other disciplines, consists of first learning the rules and then learning when to break them.
~ Joshua Bloch
One advantage of static factory methods is that, unlike constructors, they have names.
~ Joshua Bloch
Collection or an appropriate subtype is generally the best return type for a public, sequence- returning method.
~ Joshua Bloch
Writing concurrent programs in Java keeps getting easier, but writing concurrent programs that are correct and fast is as difficult as it ever was.
~ Joshua Bloch
and then tried to use it outside the classroom, you know that there are three things you must master: how the language is structured (grammar), how to name things you want to talk about (vocabulary), and the customary and effective ways
~ Joshua Bloch
If you export a nontrivial interface, you should strongly consider providing a skeletal implementation to go with it. To the extent possible, you should provide the skeletal implementation via default methods on the interface so that all implementors of the interface can make use of it.
~ Joshua Bloch
You can put any element into a collection with a raw type, easily corrupting the collection's type invariant (as demonstrated by the unsafeAdd method on page 119); you can't put any ele- ment (other than null) into a Collection>.
~ Joshua Bloch
arrays are covariant. This scary-sounding word means simply that if Sub is a subtype of Super, then the array type Sub[] is a subtype of the array type Super[]. Generics, by contrast, are invariant: for any two distinct types Type1 and Type2, List is neither a subtype nor a supertype of List. You might think this means that generics are deficient, but arguably it is arrays that are deficient.
~ Joshua Bloch
A forEach operation that does anything more than present the result of the computation performed by a stream is a "bad smell in code," as is a lambda that mutates state.
~ Joshua Bloch
streams do not make iteration obsolete
~ Joshua Bloch
In summary, serialization is dangerous and should be avoided. If you are designing a system from scratch, use a cross-platform structured-data representation such as JSON or protobuf instead. Do not deserialize untrusted data. If you must do so, use object deserialization filtering, but be aware that it is not guaranteed to thwart all attacks. Avoid writing serializable classes. If you must do so, exercise great caution.
~ Joshua Bloch
In other words, if you accept the default serialized form, the class's private and package-private instance fields become part of its exported API, and the practice of minimizing access to fields loses its effectiveness as a tool for information hiding.
~ Joshua Bloch
premature optimization is the root of all evil. —Donald E. Knuth [
~ Joshua Bloch
In other words, it is about 50 times slower to create and destroy objects with finalizers.
~ Joshua Bloch
In fact, two-thirds of the uses of the close method in the Java libraries were wrong in 2007.
~ Joshua Bloch
There is no way to extend an instantiable class and add a value component while preserving the equals contract, unless you're willing to forgo the benefits of object-oriented abstraction.
~ Joshua Bloch
Given all the problems associated with Cloneable, new interfaces should not extend it, and new extendable classes should not implement it.
~ Joshua Bloch
It is too early to say whether modules will achieve widespread use outside of the JDK itself. In the meantime, it seems best to avoid them unless you have a compelling need.
~ Joshua Bloch
The behavior of this program is counterintuitive because selection among overloaded methods is static, while selection among overridden methods is dynamic.
~ Joshua Bloch
To summarize, just because you can overload methods doesn't mean you should.
~ Joshua Bloch
This leaves a big question unanswered. Is it ever appropriate to store an optional in an instance field? Often it's a "bad smell": it suggests that perhaps you should have a subclass containing the optional fields. But sometimes it may be justified.
~ Joshua Bloch
When used to best advantage, exceptions can improve a program's readability, reliability, and maintainability. When used improperly, they can have the opposite effect.
~ Joshua Bloch
Given the difficulty of using wait and notify correctly, you should use the higher-level concurrency utilities instead.
~ Joshua Bloch
A second advantage of static factory methods is that, unlike constructors, they are not required to create a new object each time they're invoked.
~ Joshua Bloch