Browsing 7239 questions and answers with Jon Skeet
I'm not sure I really like it as an idea - but you could do this by making Attribute generic: public static class Attributes { public static Attribute<int> Age = new Attribute<int>("age"); public static... more 7/25/2015 7:35:15 PM
Why do I have to cast BonusCell even if I am using an if is statement to verify that it is a BonusCell? Because the is operator doesn't change the compile-time type of the expression board.grid[x, y].gameEntity. (In this case, I guess... more 7/25/2015 5:29:34 PM
Warning: a lot of people don't differentiate between "parameter" and "argument". They should, but they don't - so you may well see a lot of pages with incorrect uses of the terms. When you declare a method or constructor, the parameters... more 7/25/2015 9:34:03 AM
It seems to me that you need two generic type parameters: public void Import<TBehavior, TDomain>() where TBehavior : BehaviorClass<TDomain> where TDomain : IDomainObj { var instance = (TBehavior)... more 7/24/2015 8:16:23 PM
Your fields are all static: private static float deltaTime = 1.0f; private static bool AutoRun = false; private static bool AutoRunBought = false; private static bool Start = false; So if you write: Bar x = new Bar(); Bar y = new... more 7/24/2015 5:12:47 PM
There are two problems here: You're using an invalid time zone ID (you want America/New_York) You're parsing using a formatter that hasn't got a time zone set (so it'll use the default time zone) and then setting the time zone in the... more 7/24/2015 4:11:07 PM
Don't use the system defaulting at all. Use ThreadLocal<T>: either a ThreadLocal<TimeZone>, or better, a ThreadLocal<ZoneId> with the java.time classes. Then you can fetch from there everywhere that you need the... more 7/24/2015 3:04:23 PM
If you know the start and end, it's simple just to write a method using an iterator block to do this: public static IEnumerable<DateTime> DateRange(DateTime startInclusive, DateTime endInclusive) { for (var current =... more 7/24/2015 2:14:19 PM
This is just integer overflow, where the value is effectively leaking into the sign bit. It's simpler to reason about it with sbyte, for example. Think about the bitwise representations of 127 and -127 as signed bytes: 127:... more 7/24/2015 12:28:52 PM
It sounds like you can just use map with a condition: List<String> list2 = list .stream() .map(str -> someCondition(str) ? doSomething(str) : doSomethingElse(str)) .collect(Collectors.toList()); Short but complete... more 7/24/2015 11:47:01 AM