Browsing 7239 questions and answers with Jon Skeet

Trying to understand statics is java, Why is it that this is the output in this code?

class Cup { Cup(int marker) { System.out.println("Cup(" + marker + ")"); } void f(int marker) { System.out.println("f(" + marker + ")"); } } class Cups { ...
Jon Skeet
people
quotationmark

The only time that new Cup() is called is within the static initializer block for Cups. That will only be executed once, however many instances of Cups you create - indeed, even if you don't create any instances of Cups, so long as you... more 2/21/2015 8:41:51 AM

people

Java: Comparing an input to everything in a list without using a loop?

This is for a Hangman game. I am using a SortedSet to store the guesses that the user inputs. These letters are stored as char. What I am trying to do is compare each character in...
Jon Skeet
people
quotationmark

Well to start with it sounds like you should change your method's return type and parameters - you want a set of letters, after all. And sets have a contains method. So I think you want something like: public static String... more 2/20/2015 6:47:17 PM

people

NullPointerExceptionException; "AWT EventQueue 0"

I always get this error in the console when I'm running my program: java.lang.NullPointerExceptionException in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException:...
Jon Skeet
people
quotationmark

It's not clear to me why you'd get a NullPointerException wrapping the IndexOutOfBoundsException, but this is the problem: for (int i = 1; i < messwerte.size(); i ++ ) { g.setColor(Color.MAGENTA); ... more 2/19/2015 7:07:42 PM

people

JSON Convert Deserialize Object

I have an issue with my JSON to XML code. It's not assigning the values to the Object and I cannot figure out why. Please let me know what I am doing wrong. My C# code: using...
Jon Skeet
people
quotationmark

The problem is that your JSON contains @ signs in front of some property names. For example: "@MISMOVersionID":"2.4" There are two options here: Fix the JSON to not have that, e.g. "@MISMOVersionID":"2.4" Use JsonPropertyAttribute to... more 2/19/2015 7:04:10 PM

people

Generate Global UNIX Timestamp

I am looking to generate global UNIX Timestamp, which is same for all countries and regions. I have already make my hands dirty with UNIX Timestamp on the platform of .NET...
Jon Skeet
people
quotationmark

A Unix timestamp is defined as the number of elapsed seconds since the Unix epoch, which was a single point in time - usually defined as midnight on January 1st 1970 UTC. So the timestamp is already global - and the simplest way to... more 2/19/2015 6:35:04 PM

people

Return generic type from dictionary (else return a default generic value)

I'm trying to pass a key to a dictionary (of objects) and get the value out (which could be various types) or fallback to a default value I supplied. For example // Called from...
Jon Skeet
people
quotationmark

What you're seeing (in the first case) is that you can't unbox from int to float. What you're seeing when casting the dictionary itself is that a Dictionary<string, object> isn't a Dictionary<string, float>, which seems... more 2/19/2015 3:45:03 PM

people

Strange behavior of dynamic objects

I have a simple control method DoSomething which receives a json string, converts it to a dynamic object and tries to get the data: [HttpPost] public string DoSomething(string...
Jon Skeet
people
quotationmark

In the first case, you're using all the infrastructure of dynamic - which doesn't just use reflection to find "real" members, but also uses IDynamicMetaObjectProvider to provide support for members which are only known at execution time.... more 2/19/2015 10:47:06 AM

people

Calling async method on button click

I created Windows Phone 8.1 project and I am trying to run async method GetResponse(string url) on button click and waiting for the method to finish, but method is never...
Jon Skeet
people
quotationmark

This is what's killing you: task.Wait(); That's blocking the UI thread until the task has completed - but the task is an async method which is going to try to get back to the UI thread after it "pauses" and awaits an async result. It... more 2/19/2015 8:36:44 AM

people

Can we really call parameterless constructors default constructors?

I am very confused about the meaning of "default constructor" in C#. Many people, including my programming professor, just call any parameterless constructor "default constructor"...
Jon Skeet
people
quotationmark

It's not just MSDN that uses the term "default constructor" specifically for a constructor which is supplied either "if you don't specify anything else" or "always, for a struct (pre C# 6)" or "always, for a struct, unless you specify your... more 2/19/2015 7:15:04 AM

people

In what way is a static class implicitly abstract?

Jon Skeet, in his book C# in Depth, says about a static class: It can't be declared as abstract or sealed, although it's implicitly both. An abstract class is meant to be...
Jon Skeet
people
quotationmark

What does Skeet mean by a static class being both abstract and sealed? I mean that that's the representation in the IL. For example: static class Foo {} Generates IL of: .class public abstract auto ansi sealed beforefieldinit... more 2/18/2015 7:58:18 PM

people