Browsing 7239 questions and answers with Jon Skeet

Event is called after unsubscription

I'm using an object (EventReceiver) that registers a member to an event of an object (EventSource) imported via ctor. The EventReceiverimplements IDisposable and unsubscribes...
Jon Skeet
people
quotationmark

If you've got two threads - one calling the event handlers, and one unsubscribing - there will always be a race condition, where you end up with the following ordering: Event-raiser starts to raise the event Event-unsubscriber... more 5/19/2014 11:54:07 AM

people

Why default constructor cannot handle exception type Exception?

I want to know that why i have to define an explict constructor because i am getting error which says that default constructor cannot handle exception type Exception thrown by...
Jon Skeet
people
quotationmark

Yes - your Example class is effectively declaring: public Example() { super(); } That won't compile, because the super() call is calling the A() constructor which is declared to throw Exception, which is a checked exception. That's... more 5/19/2014 10:44:42 AM

people

Get all c# Types that implements an interface first but no derived classes

related to Getting all types that implement an interface we can easily get all Types in the Assembly that implements a specific interface. Example: interface IFace { } class...
Jon Skeet
people
quotationmark

Firstly, I'd use Type.IsAssignableFrom rather than GetInterfaces, but then all you need to do is exclude types whose parent type is already in the set: var allClasses = types.Where(type => typeof(IFace).IsAssignableFrom(type)) ... more 5/19/2014 10:18:42 AM

people

How to convert a list of objects to a JSON object?

I have a HashSet of objects that I am trying to put on a JSON object. HashSet<Users> users; ... JSONObject j = new JSONObject(); j.put("users", users); However,...
Jon Skeet
people
quotationmark

The problem is with your Users class. You appear to be expecting it to just pick up the fields, but I don't believe JSONObject does that - instead, it finds bean-like getters. If you try to convert a single instance of your Users class to... more 5/19/2014 8:07:31 AM

people

Linq Select into New Object Performance

I am new to Linq, using C#. I got a big surprise when I executed the following: var scores = objects.Select( i => new { object = i, score1 = i.algorithm1(), ...
Jon Skeet
people
quotationmark

Yes, you've discovered that LINQ uses deferred execution. This is a normal part of LINQ, and very handy indeed for building up queries without actually executing anything until you need to - which in turn is great for pipelines of multiple... more 5/18/2014 8:28:45 PM

people

BayazitDecomposer inaccessible when upgrading from Farseer 3.3.1 to Farseer 3.5

I used the following code in Farseer 3.3.1 and it worked correctly, but in Farseer 3.5, I always get an error message in the following line: list =...
Jon Skeet
people
quotationmark

Well, it's simply that the author of the package has changed the class from public to internal. As far as I can see, that happened in commit 101636. This is a breaking change, so should not have been done in a minor version IMO - but... more 5/18/2014 7:01:37 PM

people

Generics IAbstract<T> inherits from IAbstract

I am trying to achieve something like this: interface IAbstract { string A { get; } object B { get; } } interface IAbstract<T> : IAbstract { T B { get;...
Jon Skeet
people
quotationmark

Very nearly. Three things: You should use new in IAbstract<T> to indicate that you know you're hiding an existing member: new T B { get; } But even without that, you'll still only get a warning. You need to implement the... more 5/18/2014 5:29:17 PM

people

Erlang server, Java client TCP messages get split?

As the title says, I have a server written in Erlang, a client written in Java and they are communicating through TCP. The problem that I am facing is the fact that gen_tcp:recv...
Jon Skeet
people
quotationmark

This makes me wonder if it is something that can be fixed on the Java side? No, absolutely not. Regardless of why you don't happen to see the problem with an Erlang client, if you aren't putting any sort of "message boundary"... more 5/18/2014 4:32:27 PM

people

Incorrect date conversion by SimpleDateFormat

I am using SimpleDateFormat to convert the date from dd-MM-yyyy to yyyy-MM-dd but I does not display the year properly.I am trying to convert 18-5-2014 to 2014-05-18 but I am...
Jon Skeet
people
quotationmark

I suspect you didn't read the documentation for the (deprecated) Date constructor you're using: Parameters: year - the year minus 1900. month - the month between 0-11. date - the day of the month between 1-31. Avoid using Date... more 5/18/2014 1:21:30 PM

people

Easily convert Map<String, Object> to Map<String, String>

An API I am using has a method that returns a Map<String, Object>, but I know the Object's are String's in this case, so I want it as a Map<String, String>. But for...
Jon Skeet
people
quotationmark

Well you can't safely cast it to a Map<String, String> because even though you know you've only got strings as the values, the compiler doesn't. That's like expecting: Object x = "foo"; String y = x; to work - it doesn't; you need... more 5/18/2014 11:32:51 AM

people