Browsing 7239 questions and answers with Jon Skeet

Java UTF 8 encoding produces incorrect output

In Java, I've been trying to write a String to a file using UTF-8 encoding which will later be read by another program written in a different programming language. While doing...
Jon Skeet
people
quotationmark

I suspect the problem is that you're using a string literal in your Java code using an editor which writes it out in one encoding - but then you're compiling without specifying the same encoding. In other words, I suspect that your "£"... more 3/1/2014 9:00:21 PM

people

How to access base class method after downcasting?

This is a Java Generics program that implements a custom interface with set(T t), get() and print(T t) methods. The class that I use is called Animal. It takes a T argument...
Jon Skeet
people
quotationmark

The problem is that you're still trying to call the method on o, which is still of type Object (in terms of the compile-time type of the variable, which is all the compiler cares about). If you call the method on oAnimal instead, it will... more 3/1/2014 8:37:29 PM

people

Concurrent execution of async methods

Using the async/await model, I have a method which makes 3 different calls to a web service and then returns the union of the results. var result1 = await...
Jon Skeet
people
quotationmark

How would I go about letting them execute in parallel and join the results as they complete? The simplest approach is just to create all the tasks and then await them: var task1 = myService.GetData(source1); var task2 =... more 3/1/2014 5:06:12 PM

people

no enclosing instance of type... in scope

I investigate java inner classes. I wrote example: public class Outer { public Outer(int a){} public class Inner { public Inner(String str, Boolean b){} } ...
Jon Skeet
people
quotationmark

As Sotirios has said, your nested (not-inner) class doesn't implicitly have an instance of Outer to effectively provide to the Inner. You can get round this, however, by explicitly specifying it before the .super part: public... more 3/1/2014 4:41:40 PM

people

WP8 C# Parsing string to decimal FormatException

I am currently trying to parse a string, "277.968", to decimal, but I am getting a FormatException exception. I have read that I need to perform the decimal parse this...
Jon Skeet
people
quotationmark

Printing the lenght of the string, it reported it being 80 chars long. Right, well that's the problem then. Your string isn't "277.968" - it's "277.968\0\0\0\0\0\0(...)" - and that can't be parsed. My guess is that you've read this... more 3/1/2014 2:45:30 PM

people

Initialising date with Date(milliseconds) constructor

JavaDoc for Date class states that public Date(long date) Allocates a Date object and initializes it to represent the specified number of milliseconds since the...
Jon Skeet
people
quotationmark

The problem is here: 25*60*60*24*1000 All of this is being performed in integer arithmetic - and that value is overflowing. You can see that if you perform the arithmetic using long values instead, and show the result compared to... more 3/1/2014 12:24:09 PM

people

How to install Dev Express for Visual C# Express 2010?

I have Visual C# Express 2010 installed on my machine to develop windows application. I read about and have used dev express with visual studio 2010. So I wanted to install dev...
Jon Skeet
people
quotationmark

You can't - this isn't a Dev Express limitation per se, but a limitation of the Express SKUs of Visual Studio: they don't allow plugins to be installed. So the same is true for ReSharper, NCrunch etc. It's one of the differentiation... more 3/1/2014 10:41:21 AM

people

how to instantiate set of map in java correctly?

I want to have a Set < Map <Character, Integer> > instance. However I can't instantiate it with new HashSet < HashMap<Character, Integer> >. I have to...
Jon Skeet
people
quotationmark

It's simpler to show you an equivalent situation - let's use Object and String in the place of Map<Character, Integer> and HashMap<Character, Integer>. Suppose we could write Set<Object> set = new... more 3/1/2014 8:42:29 AM

people

Xamarin: existing vb or c# code

Does anyone have experience with Xamarin trying to use allready existing .NET code? Especially Form.Elements - or do they have to be redesigned for java(Android)? My second...
Jon Skeet
people
quotationmark

No, you can't use Windows Forms code in Xamarin. The idea of Xamarin is that it uses the UI framework which is native to the OS you're writing for - so that isn't portable - but you can share the business logic which will be common to all... more 2/28/2014 1:25:37 PM

people

Can I set Eclipse to ignore "Unhandled exception type"

Is it possible to get Eclipse to ignore the error "Unhandled exception type"? In my specific case, the reason being that I have already checked if the file exists. Thus I see no...
Jon Skeet
people
quotationmark

Is it possible to get Eclipse to ignore the error "Unhandled exception type FileNotFoundException". No. That would be invalid Java, and Eclipse doesn't let you change the rules of the language. (You can sometimes try to run code which... more 2/28/2014 10:45:45 AM

people