Browsing 7239 questions and answers with Jon Skeet

How to determine what block isn't covered here?

I have a block of code like this (class/property names have been changed to meet company guidelines): if (output.ExecutionStatus == RuleExecutionStatus.Success && ...
Jon Skeet
people
quotationmark

It sounds like you haven't got a test where the execution status isn't success - in other words, the first operand of your && expression is true for all tests, so you're not checking that it's relevant. (In general, if you can... more 5/1/2014 1:57:59 PM

people

Windows 1252 encoding through byte[]

I'm making use of the Setup... methods (such as SetupGetLineText) to read some content from inf files (I need this, not interested in a generic ini parser). These methods use...
Jon Skeet
people
quotationmark

You're currently converting a string to Windows-1252 and then converting it back to a string by interpreting those bytes as UTF-8. That is not working fine - that's broken, basically. If you've already got a string, it's not in... more 5/1/2014 1:50:22 PM

people

Joda Time: Why does Month value default to Jan regardless of date input?

This is my first time using Joda-Time. Why does the month default to January? It doesn't matter what month values i enter as date including (1-12) or (Jan-Dec). All default to...
Jon Skeet
people
quotationmark

You're using DD in your format string, which means "day of year". So after parsing the month as April, you're then going to the 30th day of the year, which is in January... You want dd, for "day of month". When in doubt, if a format... more 5/1/2014 1:21:51 PM

people

Convert and Append string into existing byte array

I am working on converting and existing C# project over to Java/Android. I am looking for the Java equivalent to UTF8Encoding.GetBytes(String, Int32, Int32, Byte[], Int32). Take a...
Jon Skeet
people
quotationmark

Okay, given that you mean ASCII rather than UTF-8, there are two immediate options: Intermediate byte array byte[] encodedText = text.getBytes(StandardCharsets.US_ASCII); System.arraycopy(encodedText, 0, data, 6,... more 5/1/2014 1:08:56 PM

people

Why is ArrayList able to remove this?

In Integer Wrapper classes ,whenever we compare like this Integer a=546; Integer b=546; System.out.println(a==b); it returns false,but then why when there is a...
Jon Skeet
people
quotationmark

Because ArrayList.remove doesn't use reference identity (which is what you get with ==) - it uses equals. From the documentation: Removes the first occurrence of the specified element from this list, if it is present. If the list does... more 5/1/2014 12:22:54 PM

people

What is the way to insert a colon(:) after every two characters in a string?

I am trying to figure out that - INPUT: String data = "506313B5EA3E"; OUTPUT: String data = "50:63:13:B5:EA:3E"; I tried...
Jon Skeet
people
quotationmark

Two simple options involving loops, both assuming you have already checked that the input is non-empty and has an even number of characters: Use StringBuilder StringBuilder builder = new StringBuilder(data.length() * 3 / 2 - 1); for (int... more 5/1/2014 8:39:34 AM

people

Why code with Object fails to complile when the same code with object works?

In the below 2 links i found that Object and object are interchangeable : Difference between Object and object c#: difference between "System.Object" and...
Jon Skeet
people
quotationmark

It's easiest not to think of object and Object as being interchangeable at all, in fact. It's better to understand object as an alias for global::System.Object. So whenever it you see global::System.Object as a type name, you can use... more 5/1/2014 6:06:04 AM

people

Casting value type constants

This is more of an academic question than one where I'm really worried about the performance. I'm just really curious is all. I've also learned in my, admittedly limited,...
Jon Skeet
people
quotationmark

The language specification helps us out here. Section 7.19 of the C# 5 spec states: A constant expression must be the null literal or a value with one of the following types: sbyte, byte, short, ushort, int, uint, long, ulong, char,... more 4/30/2014 8:07:08 PM

people

System.DateTime Kind Bits

Due to difficulties I experienced trying to call the DotNetOAuth CryptoKey constructor I started to investigate the .Net System.DateTime structure. According to what I've read,...
Jon Skeet
people
quotationmark

These longs were all different, again as expected. HOWEVER, I then tried to "inspect" the upper two bits to see which state corresponded to what settings, and found that the upper two bits were set the same in all three. I really... more 4/30/2014 7:52:22 PM

people

Converting lambda or method group to Action<T> where T is only known at runtime

I'm dynamically creating a type from a string passed to me at runtime. I have the following code at the moment: string messageType = "CustomerCreatedMessage"; //Convert the...
Jon Skeet
people
quotationmark

Given that you're not using the parameter at all, I'd create a new generic method: private static void GenericSetActive<T>(T ignored) { SetActive(true); } Then create a delegate using that: var genericMethod =... more 4/30/2014 7:45:38 PM

people