Browsing 7239 questions and answers with Jon Skeet

Disable a compiler warning which is not in the rule set

My C# application uses the Code Analysis rule set Microsoft Managed Recommended Rules. I'm using some obsolete classes so I get the warning CS0618. (I cannot replace the obsolete...
Jon Skeet
people
quotationmark

CS0168 isn't part of Code Analysis - it's a simple C# compiler warning. That's got nothing to do with any later code analysis. To disable it in project properties, go into the project properties, the Build tab, Errors and Warnings... more 2/12/2014 7:53:59 AM

people

Iterate through the items in a Listbox

I have a ListBox (sortedListBox) which I have populated like this by the items in a Combobox (allItemsComboBox): int index = sortedListBox.FindString(allItemsComboBox.Text,...
Jon Skeet
people
quotationmark

I don't know that there's any way to ask the ListBox to evaluate the ValueMember for you in that way... and because you're using an anonymous type, it becomes harder to get the value. Options: Use a named type instead, and cast each... more 2/12/2014 7:30:43 AM

people

How to OR when capturing multiple webdriver exceptions

I am trying to capture multiple exceptions like this but I get error '); expected'. How do I do it using ||? try { //find an element here }catch(...
Jon Skeet
people
quotationmark

Assuming you're using Java 7, you should be able to use this syntax: catch (StaleElementReferenceException | NoSuchElementException e) Note the single |, as well as the single variable name. See the "Catching Multiple Exception Types... more 2/12/2014 7:15:01 AM

people

switch behaviour java

Why doens't the following code throw a runtimeException? public class Test2 extends Test { public static void main(String[] args) { char[] array = new char[]{'A', '\t',...
Jon Skeet
people
quotationmark

This means there is an empty "default" in every switch or something? Sort of. If no case matches the specified value, and there's no default case, nothing happens - it's as simple as that. From section 14.11 of the JLS: If no... more 2/11/2014 8:49:04 PM

people

How Java Picks an Overloaded Method in Polymorphism

I have two classes defined as: public static class Mammal extends Animal { public void info(String s) { System.out.print("Mammal"); } } public static class...
Jon Skeet
people
quotationmark

You're overloading the method, not overriding it. Overloads are chosen at compile time, and when the compile-time type of a is Animal, then a call to a.info("test") can only resolve to the info(Object) method in Animal. If you want to... more 2/11/2014 7:26:43 PM

people

Java converting a Date to a different format

I have a date string in this format: String fieldAsString = "11/26/2011 14:47:31"; I am trying to convert it to a Date type object in this format: "yyyy.MM.dd HH:mm:ss" I...
Jon Skeet
people
quotationmark

You seem to be under the impression that a Date object has a format. It doesn't. It sounds like you just need this: Date date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse(fieldAsString); (You should consider specifying a locale... more 2/11/2014 7:20:26 PM

people

C#, Using self as a parameter for an abstract override method of the base class

How would I override DerivedZ() in the child, without having to specify a U in the base class? The latter solution appears a bit excessive. public abstract class Z {} public...
Jon Skeet
people
quotationmark

You can't use the first form, because it's not properly overriding the method. If you could do that, imagine this code: public class C : A<DerivedZ> {} A<DerivedZ> x = new B(); x.GetZ(new C()); That should work fine, after... more 2/11/2014 7:16:03 PM

people

Using StreamReader and StreamWriter for TGZ file copied from Solaris

We have a very old file delivery application(IPGear, if you have heard about it, written in tcl). We upload our IP files there and our customers download it from the...
Jon Skeet
people
quotationmark

it looks like the streamreader is not able to write this content back to disk even if we tried different encoding settings. Yes, because a tgz file isn't plain text. StreamReader and StreamWriter are for text content, not arbitrary... more 2/11/2014 6:04:22 PM

people

Can I use WPF's Full screen UI on Xamarin?

I'm thinking about starting to use Xamarin, is it possible to take a full-screen WPF project and use it on iOS and Android ?
Jon Skeet
people
quotationmark

No. Xamarin.Android and Xamarin.iOS expose the UI of the relevant platforms - you can't just use WPF on them. However, if you separate out your "business logic" from the UI logic in your application, you may well be able to use the same... more 2/11/2014 6:02:34 PM

people

Java give every instance of object an unique number

I'm having trobule writing a simple program in java. I have a class called ticket, where I have: public class Ticket { public String movieTitle = null; public static Integer...
Jon Skeet
people
quotationmark

It sounds like you're looking at movieNumber from your other class, which isn't appropriate. I would write it like this: import java.util.concurrent.atomic.AtomicInteger; public class Ticket { private static final AtomicInteger... more 2/11/2014 5:31:59 PM

people