Browsing 7239 questions and answers with Jon Skeet

Why is it wrong? about java 8 streaming

public interface Filter<M> { boolean match(M m); public static <T> Collection<T> filter(Collection<T> collection, Filter<T> filter) { ...
Jon Skeet
people
quotationmark

I'm not yet sure why you're getting that particular error, but the problem is that your method declares that it will return Collection<T>, but you're trying to assign the result to a List<T>. If you change the declaration of... more 10/23/2014 6:00:55 AM

people

Double encryption / decryption fails but single does not AES 256 bit

So this particular exception is pretty common, yet my problem is slightly different from what is usually asked. I've got a AES decrytpion and encryption function defined as...
Jon Skeet
people
quotationmark

You're using the wrong keys for decrypting. You're encrypting with key B, then encrypting the result with key A. You're then trying to decrypt that result with key B, and the final result with key A. Each time you decrypt, you should be... more 10/22/2014 4:55:46 PM

people

problems with java toLowerCase function when using arrays and multiple 'words' in the string

I am exceptionally new to java, as in, I can barely write 20 lines of basic code and have them work, level of new, I have 2 issues which may or may not be related as they are from...
Jon Skeet
people
quotationmark

This is because you're using Scanner.next(), which returns a single token - and which uses whitespace as a token separator by default. Perhaps you should use nextLine() instead, if you want to capture a whole line at a time? As for your... more 10/22/2014 4:40:07 PM

people

How to correctly use constructors?

Hi I am new to Java and constructors are still consfusing me. I am trying to create and enum as below: public enum SCardErrors { SCARD_S_SUCCESS(0x0L), ...
Jon Skeet
people
quotationmark

You've only got a constructor accepting int: private SCardErrors(int value) ... but you're trying to call it with an argument of type long: SCARD_S_SUCCESS(0x0L) You either need to change the constructor to accept a long - and... more 10/22/2014 4:13:41 PM

people

Async await how to use return values

I have a windows service that I have inherited from another developer, it runs very slow and has numerous slow call to the eBay API. I wish to speed it up without too much...
Jon Skeet
people
quotationmark

If the task returned by Task.WhenAll has completed, that means all of the tasks that you passed to it have completed too. That in turn means that you can use the Result property of each task, with no risk of it blocking. string details =... more 10/22/2014 2:40:35 PM

people

StreamCorruptedException while trying to parse a byte array in Java

I'm writing an Android app, trying to parse some binary data received via Bluetooth, containing various signed and unsigned 1-4 byte integers. I'm given to understand that the...
Jon Skeet
people
quotationmark

Unless the data has been written by ObjectOutputStream, you shouldn't use ObjectInputStream - that's very specific to Java's binary serialization. If this is just binary data, 4 bytes for a 32-bit integer etc, then you probably want... more 10/22/2014 1:17:56 PM

people

How to get XML into a dictionary in c#

I have the following XML: <Axis> <Collections> <Collection> <Client> <Name>Client 1</Name> ...
Jon Skeet
people
quotationmark

I would suggest: Not using XPath to select elements, but using the Elements() method (etc) instead Using a lookup instead of a Dictionary<string, List<string>>, via ToLookup. A lookup is like a dictionary with multiple values... more 10/22/2014 12:49:44 PM

people

HttpListener handling multiple requests

I have this HttpListener, which works perfect for a single requesst, but then it shuts down after finishing up the request. What I'm interested in, is a listener that keeps up the...
Jon Skeet
people
quotationmark

Yes - you're calling GetContext once, serving that request, then stopping. Instead, you should be calling GetContext in a loop. Depending on whether you want to be able to handle multiple requests concurrently or not, you might have... more 10/22/2014 12:41:14 PM

people

C# initialize object

The first 3 lines of code works fine.. How can I do the same when using object initializer ? // works Customer MyCustomerx = new Customer(); MyCustomerx.Location[0].place = "New...
Jon Skeet
people
quotationmark

There's no equivalent of that code within object initializers - you can't specify indexers like that. It's slightly unusual that it works even directly... I'd expect to have to add to a Locations property, rather than there being two... more 10/22/2014 10:29:49 AM

people

Error java exectuing

Im trying to execute a simple java code (I have already compiled it with no problems) but it gives me the next error: c:\Users\alejandro\Desktop java HelloWorld.java Error:...
Jon Skeet
people
quotationmark

You're specifying the name of the source file. That's not what you provide to the java command - you specify the class name. java HelloWorld This assumes that HelloWorld.class is somewhere on the classpath, which would default to "the... more 10/22/2014 9:58:00 AM

people