Browsing 7239 questions and answers with Jon Skeet
Well, there is a slight difference. Suppose the code that finds the key throws an exception. In your first code, the result would be a faulted task. In your second piece of code, the exception would immediately be thrown to the caller.... more 12/7/2014 8:33:30 PM
The simplest way of doing this is probably to make most of your code only depend on Random, with an instance being injected (e.g. by passing it into a constructor). That way, for testing purposes you can pass in a simple Random with a... more 12/7/2014 9:40:00 AM
To format a specific date (not necessarily the current date), use EEE in a SimpleDateFormat. If you want all the short days of the week, you could use DateFormatSymbols symbols = new DateFormatSymbols(locale); String[] shortDays =... more 12/6/2014 11:09:15 AM
The problem is that e24dd004 is larger than int can handle in Java. If you use long, it will be fine: String str = "e24dd004"; long hex = Long.parseLong(str.trim(),16); String... more 12/6/2014 10:06:54 AM
However, if thread one has mutated object A while it is in the collection, does getting it by thread two still provide the same full visibility guarantee? No, definitely not. The concurrency guarantees only apply to the collection... more 12/6/2014 9:51:19 AM
If you're using Java 8, you can use streams: private boolean fieldLockExists(String tableName, String fieldName, Integer id) { return getFieldLocks(tableName, id) .stream() .anyMatch(fl ->... more 12/5/2014 4:20:10 PM
You're currently just looking at the child elements of the root element. Instead, if you want to find all descendants, use Descendants. Additionally, there's no point in using a query expression of from x in y select x (or rather,... more 12/5/2014 1:48:14 PM
You shouldn't be converting the DateTime to a string and back - but your current problem is that you're converting the UTC value you get back from the server into a local DateTime for no obvious reason. Ideally, I'd suggest changing... more 12/5/2014 1:10:07 PM
If you use originalSDF.setLenient(false) then parsing "05.12.2014 13:17" will throw an exception... basically in lenient mode, hh is treated as HH (i.e. as a 24-hour value) when the value is greater than 12 (and possibly when it's... more 12/5/2014 9:57:33 AM
Basically, you shouldn't use the default string representation from the browser. Otherwise you need to know which language it's going to use for month names etc, and you're basically fighting a losing battle. I would strongly recommend... more 12/5/2014 9:34:46 AM