Advanced Topics in Programming Languages: Java Puzzlers,...
Why Stack Overflow recommends it
Stack Overflow users link it when a question hits one of the puzzler traps (ternary operator unboxing, non-generic collection methods, threads in JUnit) and want an authoritative explanation from the people who designed the libraries.
Recommended by 3 people across 3 different months, 2008 to 2014.
What it is
A Google Tech Talk from July 2007 in which Josh Bloch and Bill Pugh present eight Java Puzzlers in a game show format. Each puzzle exposes a subtle quirk of the Java language or core libraries, such as the ternary operator's result type, generics in collections, and concurrency.
What people said
Strong rec kloffy · 2010-04 · Stack Overflow · on “Java conditional operator ?: result type”
To be or not to be, that is the question. [this video] :) Edit: Actually, looking closer it seems that this case is actually a mix between the Hamlet [this video] (ternary operator and wrapped integral types) and the Elvis [this video] (auto-unboxing null) puzzlers. In any case, I can only recommend watching the video, it is very educational and enjoyable.
Recommends Nikita Rybak · 2010-06 · Stack Overflow · on “Why do we have contains(Object o) instead of contains(E e)?”
Answered here. Why aren't Java Collections remove methods generic? [LINK] In short, they wanted to maximize backwards compatibility, because collections have been introduced long before generics. And to add from me: the video he's referring is worth watching. [this video] update To clarify, the man who said that (in the video) was one of the people who updated java maps and collections to use generics. If he doesn't know, then who.
Recommends user180100 · 2010-10 · Stack Overflow · on “Weird problem using JUnit in multi-thread environment”
Take a look at [this video] (starting at 17:09), it explain problems you can get with JUnit and threads. I think, that in your case, get() throws a ExecutionException and that's why the second test fails. In the first testcase, jUnit doesn't see the exception.
Cites dmeister · 2008-09 · Stack Overflow · on “Why aren't Java Collections remove methods generic?”
Josh Bloch and Bill Pugh refer to this issue in Java Puzzlers IV: The Phantom Reference Menace, Attack of the Clone, and Revenge of The Shift [this video] . Josh Bloch says (6:41) that they attempted to generify the get method of Map, remove method and some other, but "it simply didn't work". There are too many reasonable programs that could not be generified if you only allow the generic type of the collection as parameter type. The example given by him is an intersection of a List of Number s and a List of Long s.
Cites texpert · 2013-09 · Stack Overflow · on “why this is not working - Unit testing a synchronous method using parameterized data of Junit?”
I am trying to learn the JUnit and wanted to extend it to test in a multi-threaded way. The class I want to test is PrimeNumberValidator. This just tests if a passed in number is prime or not. package com; public class PrimeNumberValidator { public Boolean validate(final Integer primeNumber) { System.out.println("Validating .............:" + primeNumber); for (int i = 2; i < (primeNumber / 2); i++) { if (primeNumber % i == 0) { return false; } } return true; } } The PrimeNumberValidatorTest is the test class. The 2 of the test data are wrong and I have done this purposely to test for failure. The test method testPrimeNumberValidator runs perfectly fine. But, the multi-threaded version testMu
Cites android developer · 2014-02 · Stack Overflow · on “How to get warned about NPE caused by functions returning null?”
Background Sometimes, functions return null on some cases, and yet whoever uses them wasn't aware of it, so NPE is inevitable . For example (and it's just an example , to show what I'm talking about) : public class Test { public static void main(final String[] args) { final int t=0; System.out.println("result:"+foo(t).toString()); // no warning here... } public static String foo(final int t) { if(t>0) return "positive"; else return null; } } The problem Eclipse doesn't warn about such a thing, and it doesn't even have it on the settings. It can detect such problems only when there are no functions involved (see my edit below). Not only that, but I can't find an annotation that says that the