Browsing 7239 questions and answers with Jon Skeet

Incorrect number of type parameters in reference class MyClass<F,T> Generic entity framework

I've got the following generic abstract class: public abstract class MyClass<F, T> where TCurrencyFrom : Book where TCurrencyTo : Book { public int Id { get;...
Jon Skeet
people
quotationmark

Unfortunately this is tricky with .NET generics. If MyClassConfiguration doesn't actually care about the type arguments, you might want to create a non-generic interface: public interface IMyClass { // Any members of MyClass<,>... more 4/14/2014 9:02:57 AM

people

How to keep an object unique

I have a static DataTable (with 80k records) in Common.DLL and that Common.DLL is referred by 10 windows services. So, instead of having 10 copies of that DataTable in the memory...
Jon Skeet
people
quotationmark

Given that the services will at least be using different AppDomains, and quite possibly different processes, sharing the same data between all of them would be tricky. I would personally suggest that you just don't worry about it - unless... more 4/14/2014 8:31:13 AM

people

LINQ IsAssignableFrom check between two Type[]?

Let's say the following types: public class Object { } public class GameObject : Object { } public class Component : Object { } public class Transform : Component { } And two...
Jon Skeet
people
quotationmark

I suspect you're just looking for: return to.Length == from.Length && to.Zip(from, (t, f) => t.IsAssignableFrom(f)) .All(x => x); The call to Zip here just zips the first elements of both sequences with... more 4/13/2014 2:03:17 PM

people

float to double giving Strange results

I came across with this behavior of float and double during type casting. I modified my actual statements to better understanding. 1...
Jon Skeet
people
quotationmark

There are several steps involved here, each with different numbers. Let's split the code up for each statement: double original = 128.12301; // Or 128888.12301 float floatValue = (float) original; double backToDouble = (double)... more 4/13/2014 11:42:55 AM

people

implicit upcasting and explicit downcasting in java

When java can implicitly do up casting , why does not it implicitly do down casting ?Please explain with some simple example? ...
Jon Skeet
people
quotationmark

The point is that upcasting will always succeed, so it's safe - whereas downcasting can fail: String x = getStringFromSomewhere(); Object y = x; // This will *always* work But: Object x = getObjectFromSomewhere(); String y = (String)... more 4/13/2014 11:37:12 AM

people

what will be if put in hashmap more than capacity

Please tell me what will be with old items in HashMap if I put more items than specify in capacity? for example: HashMap<String, Bitmap> hashmap= new HashMap<String,...
Jon Skeet
people
quotationmark

You're only specifying an initial capacity - the HashMap will grow as it needs to anyway, copying the contents internally. It's only available as an optimization, so that if you know you'll need a large capacity, you can start off with... more 4/12/2014 10:33:02 AM

people

How to make extension unionWith for Hashset

I am trying to make an extension for the custom type. This is my code. I don't know how my source becomes zero in this code. Even in the debug part hashset temp is giving me a...
Jon Skeet
people
quotationmark

This is simply a matter of parameters being passed by value in .NET by default. You're changing the value of source to refer to a different HashSet, and that doesn't change the caller's variable at all. Assuming that Condense doesn't... more 4/12/2014 10:16:12 AM

people

Display unicode characters Android

I have a json for currencies : [ { "acronym": "EUR", "currency": "Euros", "favorite": "true", "placeholder": "\\u20ac00.00 EUR", "symbol": "\\u20ac" ...
Jon Skeet
people
quotationmark

Your JSON has escaped the backslash, which means it's the JSON representation of "backslash u 20ac". All you need to do is not escape the backslash, so that \u20ac is the JSON-escaped version of the Euro symbol: "symbol": "\u20ac" I'd... more 4/12/2014 9:58:57 AM

people

Test method returning N days before today

I'm a bit confused, I have a method which returns date N day before today, However I do not now how to test it: public String getBeforeDay(int noDays){ Calendar calendar =...
Jon Skeet
people
quotationmark

What is a good practise to solve such test? The problem is that you're depending on something ephemeral: the current date/time. The fix I prefer for this is to introduce the idea of a Clock as a dependency (to be handled as with any... more 4/12/2014 9:14:31 AM

people

why my unit test failing after adding a parameter?

Here is my code when working fine verify(loginService).getUser(eq(loginName)); here it is failing.. @Test public void test_getUserFlow4() { ... LoginModel...
Jon Skeet
people
quotationmark

If you're using argument matches, you need to use them for all arguments. So to fix your test, you can just use: verify(loginService).getUser(eq(loginName),... more 4/12/2014 8:27:21 AM

people