Effective Java - Still Effective After All These Years
Why Stack Overflow recommends it
Stack Overflow users link it when explaining Java generics, wildcards, enums and ConcurrentHashMap usage, since the author of the book and of core JDK classes walks through them directly.
Recommended by 7 people across 8 different months, 2011 to 2020.
What it is
Joshua Bloch gives a Silicon Valley Web JUG talk hosted at Google, working through selected items from Effective Java, with a few Java Puzzlers before and after. It covers generics (including PECS and typesafe heterogeneous containers), enums, and concurrency advice.
What people said
Recommends lschin · 2011-05 · Stack Overflow · on “Need to use Enum”
You should look at Chapter 6 Enums and Annotations (maybe best practices for Java Enum) of Effective Java (2nd Edition) [LINK] , the author ( Joshua Bloch ) of this book is also author of JDK's Enum [LINK] , EnumSet [LINK] , EnumMap [LINK] . Or you can look at conference of Joshua Bloch, either one : - Google I/O 2008 - Effective Java Reloaded [LINK] - Effective Java - Still Effective After All These Years [this video]
Recommends Edwin Buck · 2012-03 · Stack Overflow · on “Can I use a range of values in a single switch?”
This was proposed in Project Coin some time back. Basically the switch operator now operates on built-ins and Objects. While a well defined range exists for selecting two built-ins, switches that are operating on Objects don't have a well defined range. Currently two classes of objects are supported, Strings and Enum . Is "car" between "A" and "D"? Depends on how you like to handle case sensitivity. Is MyEnum.ONE before MyEnum.TWO ? Depending on it in production code is a very bad idea (as Josh Bloch would love to explain), and if you need an ordering, the maintainable way is to implement a non-index bound comparator. This much better practice would be hard to integrate into a simple switch
Recommends VKPRO · 2013-05 · Stack Overflow · on “What is the use of recursive type bound in this case”
Best description given by Joshua Bloch. Check this video to get the best clarification. Topic starts at 22:00 Effective Java - Still Effective After All These Years [this video]
Recommends Bruno Reis · 2013-06 · Stack Overflow · on “Forcing Java generic parameters to be of the same type”
You can force the parameters to be of the same type by doing the following: // the first class, A<K>: class A<K> { void f(K x) {} } // the second class, defining the method with generic type parameters class Test { <T> void foo(A<T> a, T x) { a.f(x); // now it works! } } // a third class, that uses the above two: class Main { public static void main(final String... args) { final Test test = new Test(); final A<String> a = new A<>(); test.foo(a, "bar"); } } What this does is: the method foo defines a generic type parameter T and uses it to enforce that the K type parameter of the class A must match the type of x , the second parameter of foo . You could even impose restrictions on <T> if you
Recommends Bruno Reis · 2014-05 · Stack Overflow · on “What is the purpose of "? extends A"?”
[this video] -- best resource to start learning about co/contra-variance in Java. A talk from Joshua Bloch about some chapters on his Effective Java. Flex your PECS.
Recommends Alexandre Santos · 2014-06 · Stack Overflow · on “How to implement an interface with generic types?”
"Can anyone explain to me what I'm doing wrong?" Your tester is of type Comparable, which extends the Telemeter, which is also of the type Comparable. What you really want is that the test extends a generic object, which we normally name E and you want this object to extend the class Comparable of Es. If you replace E with Integer, for example, it will make more sense: public class TelemeterTester> implements Telemeter "I don't understand generics very well and I've been stuck on variations of this error for a few hours now." Josh Bloch has awesome videos on Youtube where he explains PECS :) It will make sense once you see them. [this video] Your code should look like this: import java.util.*; /*
Recommends Kevin J. Chase · 2017-03 · Stack Overflow · on “How to replace instanceof in the case of collection of instances by their classtype or interface”
This sounds very similar to Joshua Bloch's "Typesafe Heterogeneous Containers", although type erasure of the lists means you'd have to keep a `Map` of the generic type of each `List ` to the `List` itself. Neal Gafter's " Super Type Tokens [LINK] " might solve that for you. (Note: Gafter's link to Joshua Bloch's THC pattern is long dead. Bloch covered them in his " Still Effective After All These Years [this video] " talk, around 36mins in at the end of "Generics" (Item 29), before "Enums".)
Recommends Toerktumlare · 2020-02 · Stack Overflow · on “What is the difference between map and doOnNext in flux? (i.e project reactor)”
TLDR; Flux#doOnNext is for side effects, Flux#map is for mapping something from one type to another type, synchronously. If we look at the documentation [LINK] it says the following for doOnNext Flux<T> doOnNext(Consumer<? super T> onNext) Add behavior (side-effect) triggered when the Flux emits an item. this means in doOnNext , we can do side effects, like log, or do a rest call somewhere etc. etc. We also return a Flux of type T , that is the same that doOnNext is taking in, so no type change. If we on the other hand look at Map : Flux<V> map(Function<? super T,? extends V> mapper) Transform the items emitted by this Flux by applying a synchronous function to each item. We can read that he
Cites maaartinus · 2011-04 · Stack Overflow · on “Performance of ConcurrentHashMap.putIfAbsent”
In his talk about Effective Java [this video] at 54:15 Joshua Bloch recommends to use get before putIfAbsent in order to improve performance and concurrency. This leads me to the question why this optimization is already not build in like public V BETTER_putIfAbsent(K key, V value) { V result = get(key); if (result!=null) return result; return ORIGINAL_putIfAbsent(key, value); }
Cites Jan Koester · 2012-02 · Stack Overflow · on “Java Generics in Method Declaration”
private Map<Class<?>, Object> favorites = new HashMap<Class<?>, Object>(); public <T> void putFavorite(Class<T> type, T instance) { //code to put the T Object in the Map } I saw this code in a talk from Joshua Bloch on UserGroupsAtGoogle link: [this video] I wonder what this <T> means in the method declaration of the putFavorite method. I assume, this is not the return value, because this is already void .