Browsing 7239 questions and answers with Jon Skeet

Convert Date to Milliseconds in Java

I need to convert a Date to its corresponding Milliseconds format.I am using getTime() method of Date class in Java for this. But the milliseond generated is not of my actual...
Jon Skeet
people
quotationmark

1416594600000 corresponds to 2014-11-21T18:30:00Z. In other words, 6.30pm on November 21st 2014 in UTC. Epoch Converter is a great resource for checking things like that. Now, a Date object doesn't have any time zone information itself.... more 7/18/2014 5:07:49 AM

people

How to give a blank line to an InputStream using IOUtils.toInputStream

I have code which consumes an InputStream through a Scanner which looks like String input = scanner.nextLine().toLowerCase(); if (input.isEmpty()) { return defaultAnswer; }...
Jon Skeet
people
quotationmark

Either using IOUtils.toInputStream("") or new ByteArrayInputStream(new byte[0]) may work. The latter would certainly provide an empty stream, but it may make your code fail because there isn't an empty line to read - there's no line... more 7/18/2014 4:57:51 AM

people

tcpClient and IRC client issues

Can someone tell me why the following code isn't working? using System; using System.IO; using System.Net.Sockets; using System.Text; using System.Threading; using...
Jon Skeet
people
quotationmark

You're not including a line break after the PING or USER messages. From RFC 2812: IRC messages are always lines of characters terminated with a CR-LF (Carriage Return - Line Feed) pair So you should have: this.writer.Write("PASS... more 7/17/2014 5:47:50 AM

people

how to inherit Part of Constructor from super class to sub class in java

How to inherit some parameters of superclass constructor to subclass constructor? For example I want only weight and height to be inherited to subclass, how to construct the...
Jon Skeet
people
quotationmark

Either you need to supply a mood to the constructor in the superclass (possibly as a constant), or you need to add a constructor to the superclass which doesn't take a mood. You need to ask yourself whether every Question/People really... more 7/17/2014 4:46:38 AM

people

Timer skipping on Nexus device running 4.2

I have recording functionality in my application. I'm using a handler with refresh rate of 1000ms to update the handler for timer. Its working fine with no skipping of seconds in...
Jon Skeet
people
quotationmark

If you've got a timer updating every 1000ms, then if it happens to take a bit more than 1000ms between calls and you're unlucky enough to be close to a second boundary, then you would see it "skip" a second sometimes. For example, suppose... more 7/17/2014 4:35:23 AM

people

Implementing an interface with a return type that implements the required return type

Why can't I do this? IHasOperatingSystem { IOperatingSystem OperatingSystem { get; } } Computer<T> : IHasOperatingSystem where T : IOperatingSystem { public T...
Jon Skeet
people
quotationmark

It's telling me that the type should be IOperatingSystem, but if T implements IOperatingSystem, shouldn't that be sufficient? No. That's just not the way C# works. In order to implement an interface, or override a method, the... more 7/16/2014 7:48:32 PM

people

IEqualityComparer and Linq Distinct Hard Code GetHashCode()

I have an array of CustomObject s and a custom IEqualityComparer<CustomObject>. I have hard coded the IEqualityComparer.GetHashCode() method to return a constant 42. ...
Jon Skeet
people
quotationmark

When I run linq's Distinct method on the array, nothing is filtered out. Anyone know why? Yes - Equals is going to return false for any two distinct objects. Within your Equals implementation, you're calling the... more 7/16/2014 1:47:02 PM

people

How to Remove multiple items in List using RemoveAll on condition?

I tried like following. MyList.RemoveAll(t => t.Name == "ABS"); MyList.RemoveAll(t => t.Name == "XYZ"); MyList.RemoveAll(t => t.Name == "APO"); Instead how can I do...
Jon Skeet
people
quotationmark

You only need one lambda expression - the || goes within that: MyList.RemoveAll(t => t.Name == "ABS" || t.Name == "XYZ" || t.Name == "APO"); In other words, "Given a t, I want to remove the element if t.Name is ABS, or if t.Name is... more 7/16/2014 12:23:07 PM

people

Syntax to move backwards in LinkedList?

i know that LinkedLists are implemented in a doubly linked way, so each node has a next and a previous pointer. however, i couldn't find what syntax to use to access the previous...
Jon Skeet
people
quotationmark

LinkedList has a listIterator(int) method. So you can use: // Start at the end... ListIterator<Foo> iterator = list.listIterator(list.size()); while (iterator.hasPrevious()) { Foo foo = iterator.previous(); } That doesn't... more 7/16/2014 7:17:33 AM

people

Automagically convert properties to auto getter/setter

I've generated a code base for service communication from a WSDL file which resulted in around 100 classes containing the following: public class SomeClass { private string...
Jon Skeet
people
quotationmark

If you just need to do this once, you can let R# do it for you with a Code Cleanup action. Right-click on the project (or solution, or single source file), select "Cleanup code..." and then use profile which includes "Use auto-property,... more 7/15/2014 4:26:29 PM

people