Browsing 7239 questions and answers with Jon Skeet

Unwanted backslash added to file saved by java method

In my spring project, one of my service classes has this method to save a file named database.properties in disk: public void create_properties(String maquina, String usuario,...
Jon Skeet
people
quotationmark

It's doing exactly the right thing - you're saving a properties file, which escapes things like colons using backslashes. From the documentation for Properties.store: Then every entry in this Properties table is written out, one per... more 5/10/2014 12:51:21 PM

people

Parse svn log xml date output using SimpleDateFormat

The date format of the xml output of the svn log command is like the following. 2014-04-24T08:51:58.213757Z I tried to parse this to a util.Date object using SimpleDateFormat...
Jon Skeet
people
quotationmark

You need to quote the T because you want it to match literally. You also want X as the format specifier for the time zone, not Z: yyyy-MM-dd'T'HH:mm:ss.SSSSSSX Or you could specify the time zone as UTC, and quote the Z as... more 5/10/2014 10:24:10 AM

people

How do I access parameters and methods defined across two interface from a class that implements those two interfaces?

In my factory I'm generating my object based on one interface, but it implements two. for example myClass1 : Interface1, Interface2 { string blah; int num; } myClass2 :...
Jon Skeet
people
quotationmark

You don't need to cast to the concrete class - just cast to the interface you're interested in (or use as to perform a conditional cast, and check it for success): Interface1 x = (Interface1) Activator.CreateInstance(type); Interface2 y =... more 5/9/2014 9:49:18 PM

people

Why is my output from System.out.println differ from bufferedwriter?

I am trying to capture the directory listing, including subdirectories and files. I would like to write out the content to a text file. I am having a problem with differing output...
Jon Skeet
people
quotationmark

You're creating a new BufferedWriter each time you recursively call the method. I'm surprised that's working at all, but it certainly makes it hard to tell what the output is likely to be. I suggest you change the code to have an "outer"... more 5/9/2014 5:19:11 PM

people

Correct way to see if the current instance of a superclass is a subclass from within the superclass

Say I have a class called SuperClass and a class called SubClass. SubClass extends from SuperClass. Inside the definition of SuperClass I have a method that intends to check if...
Jon Skeet
people
quotationmark

I think you're just looking for the is operator: if (this is SubClass) In particular, that will also continue if this is an instance of a subclass of SubClass. If you then want to use this as SubClass, e.g. to get at a member declared... more 5/9/2014 4:26:34 PM

people

Why remove handler of timer?

I have a question regarding something I'm seeing in some VB.NET code on a project that I've had to take over. In a form the developer has declared a very simple 15sec...
Jon Skeet
people
quotationmark

I believe this is basically stopping the timer No, it's removing a single handler. If there are any other handlers, those will keep firing. Or maybe the developer wants to be able to re-add the handler later on, with the timer keeping... more 5/9/2014 1:10:55 PM

people

Why does a compiler generated IEnumerator<T> hold a reference to the instance that created it?

While working on a project, I wrote an iterator block similar to the following: public class Sequence<T> : IEnumerable<T> { public T Head{get; private set;} ...
Jon Skeet
people
quotationmark

Logically your first method should capture this. This line: Sequence<T> collection = this; ... will only execute on the first call to MoveNext(), so it really does need to capture it, and it can only capture it in an instance... more 5/9/2014 12:48:34 PM

people

Java simple generics

How can I replace those 2 functions with one using something like C++ tempates? public void verify(final int[] array, final int v) { for ( final int e : array ) if ( e == v...
Jon Skeet
people
quotationmark

You can't, basically. Java generics don't work with primitive types. You could do it with reflection, but it would be ugly. You could also do it with the boxed types, like this: public <T> void verify(T[] array, T value) { if... more 5/9/2014 12:40:03 PM

people

Calling System.out.println() through a lambda expression

In C# I can write the following code: public static Action<object> WL = x => Console.WriteLine(x); ... and then every time that I want to write something out to the...
Jon Skeet
people
quotationmark

Your current attempt doesn't work because you're trying to declare a variable of type void - the equivalent would fail in C# too. You need to declare a variable of a suitable functional interface, just like you use a delegate type in... more 5/8/2014 11:45:44 PM

people

Conway's Game of Life in PyGame not generating correct patterns

I'm trying to make conway's game of life in python using pygame. I can't figure out why but the patterns its generating are way off. I've looked through the code a million times...
Jon Skeet
people
quotationmark

I suspect this is the problem: cells[x][y] = update(cells,x,y) You've only got one grid, which you're updating while you're still computing from it. Generation n+1 should only take account of information from generation n - whereas... more 5/8/2014 10:04:23 PM

people