Browsing 7239 questions and answers with Jon Skeet

Why won't this 'if' statement run in a while loop without something else also happening in the while loop?

I'm having a problem where an if statement is only running if there is something else happening before it in the while loop. Here is the code I want to use: public void load()...
Jon Skeet
people
quotationmark

If it makes a difference, the code I've shown above is running in a separate thread. And that's the problem. You're relying on a value set by one thread to be visible in another - and there's no such guarantee without memory barriers... more 7/11/2015 10:28:45 AM

people

Why can't object of nested class be used as a parameter of supertype constructor?

I have code like the following: class A { final Object data; A(Object _data) { data = _data; } class B extends A { B() { super(new C()); } ...
Jon Skeet
people
quotationmark

With a simple nested class, it would be fine. However, you're creating an inner class of B, which means you're implicitly passing a reference to an instance of B - which would be this in this case, and you can't use this before super(...)... more 7/10/2015 3:29:58 PM

people

rounding up negative floating literal java

Why does -0.5 when being passed on the Math.round results to 0? and 0.5 when being passed also results to 1? shouldn't it be that when you pass -0.5 to Math.round() should also...
Jon Skeet
people
quotationmark

Math.round(double) is documented as: Returns the closest long to the argument, with ties rounding to positive infinity. So -0.5 is rounding up (towards positive infinite) instead of down towards negative infinity. It's behaving... more 7/10/2015 3:27:39 PM

people

C# `foreach` behaviour — Clarification?

I've read Eric's article here about foreach enumeration and about the different scenarios where foreach can work In order to prevent the old C# version to do boxing , the C# team...
Jon Skeet
people
quotationmark

MyEnumerator does not has the required public methods Yes it does - or rather, it would if Current were public. All that's required is that it has: A public, readable Current property A public MoveNext() method with no type... more 7/10/2015 2:10:54 PM

people

type cast rule in java

So known fact: (byte)1 ^ (byte)1 results in an int (per the spec). Can someone explain to me why the following is possible without explicit cast (from int to byte)? byte myByte...
Jon Skeet
people
quotationmark

This: (byte)1 ^ (byte)1 is a constant expression (JLS 15.28), which is known to be in the range of byte. You can therefore implicitly convert it to byte in an assignment context (JLS 5.2): In addition, if the expression is a... more 7/10/2015 2:05:21 PM

people

Format date with timezone in angularjs

Using angularjs 1.2.26 i cant format my date input to the desired timezone, here's an example: http://plnkr.co/edit/CxCqoR3Awcl1NFrCZYjx?p=preview {{'2015-07-10T12:37:08Z' | date...
Jon Skeet
people
quotationmark

There are two problems: The time zone support looks like it was introduced post-1.2.26 The time zone support doesn't take an arbitrary TZDB ID. From the docs for v1.4.1: Timezone to be used for formatting. It understands UTC/GMT and... more 7/10/2015 1:55:01 PM

people

Why does ObservableCollection<T> implement INotifyPropertyChanged?

In .NET 4.0, there isn't a single property defined by ObservableCollection<T> nor does it override any property of its parent or interfaces. So why does...
Jon Skeet
people
quotationmark

Both Count and Item[] changes are notified. Here's a sample (using C# 6 just for the string interpolation): using System; using System.ComponentModel; using System.Collections.ObjectModel; class Test { static void Main(string[]... more 7/10/2015 1:47:56 PM

people

Performance in linq to entity queries between linq and lambda?

I have a doubt in a query that it's a little bit slow and i want to know what's best for performance. Let's present this first example: var result = from tableA in...
Jon Skeet
people
quotationmark

It would be exactly the same. Query expressions are basically converted to the non-query-expression equivalent. You'd need to use select new { tableA, tableB } or something similar anyway, so that you could use both variables after... more 7/10/2015 1:41:58 PM

people

GitHub for Windows does not see changes in repository

I have created a repository using GitHub for Windows (GfW) and added 3 commits and synced using aforementioned. Commits were visible on GitHub webpage and in my app. Then my...
Jon Skeet
people
quotationmark

Well, there are four repositories involved here: Your github one Your local clone of your github project Your brother's github fork Your brother's local clone of his fork I haven't used GfW myself for a little while, but I suspect that... more 7/10/2015 10:53:59 AM

people

Getting a count of unique strings from a List<string[]> into a dictionary

I want to input a List<string[]> and The output is a dictionary where the keys are unique strings used for an index and the values is an array of floats with each position...
Jon Skeet
people
quotationmark

It sounds like you could use something like: var dictionary = doc .SelectMany(array => array) .Distinct() .ToDictionary(word => word, word => doc.Select(array => array.Count(x => x == word)) ... more 7/10/2015 10:14:10 AM

people