Browsing 7239 questions and answers with Jon Skeet
The answer is that it does break subclasses, potentially. It's easy to show that: BrokenSet.java: import java.util.*; public class BrokenSet<E> extends HashSet<E> { private final List<E> list = new... more 5/2/2015 7:06:23 PM
I have a class with some static variables and I want to create multiple independent instances of this class. In that case you just don't want static variables. static means "associated with the type rather than an instance of the... more 5/2/2015 3:36:14 PM
It's not at all clear that you should expect Literal1.Text += ... to be thread-safe. I would suggest you use the Parallel.For loop just to collect the data, and then change Literal1.Text afterwards. For example, you could write: var... more 5/2/2015 9:17:31 AM
You should almost certainly create a class to represent those three values together, if they're meaningful. I'd personally then write a static parse method. So something like: public final class Person { private final int x; ... more 5/2/2015 8:46:28 AM
You've created an ArrayList<Car> - you can only add elements to that list that the compiler knows to be cars. So you could use: list.add((Car) c); or more simply, just declare the type of c to be Car to start with: Car c = new... more 5/2/2015 7:28:08 AM
You're using YYYY which is the week-year instead of the "normal" year. That's usually only used with day-of-week and week-of-year specifiers. The exact behaviour here would be hard to explain - feasible, but not terribly helpful.... more 5/1/2015 2:44:53 PM
Well, you need to ask yourself what's special about T here. Suppose we were to write: public static void Add(this IEnumerable<X> items, X item) ... would you expect that to work? If so, consider: public static void Add(this... more 5/1/2015 12:48:20 PM
Can I get round this so that I only suppress the warning in the method where the assembly is called? Yes - by using the normal way of suppressing warnings in C# - using #pragma warning disable. Here's an example: using... more 5/1/2015 10:33:55 AM
I suspect you're meant to be using System.Collections.ArrayList which is non-generic - so you'd have: var books = new ArrayList { new Book("Moby Dick", 254) }; Of course, using non-generic collections is generally a bad idea, and unless... more 5/1/2015 9:50:29 AM
Yes, if you want to read resources from inside a jar file, you shouldn't use FileInputStream. Perhaps you should add a readResource method: public static Object readResource(Class clazz, String resource) throws IOException,... more 5/1/2015 9:24:28 AM