Browsing 7239 questions and answers with Jon Skeet

Difference between suppressedException and cause

I have my own exception, thrown by my class, BrowserException. It may be because some internal problem, i.e. UnsupporderEncodingException. Now I have 2 options: ...
Jon Skeet
people
quotationmark

A suppressed exception is one which would have happened if another exception hadn't occurred. I'm only aware of one case where this happens, which is with a try-with-resources statement. The JLS (14.20.3) says: Resources are closed in... more 10/11/2017 7:12:33 AM

people

Joda time off by one error when counting days after 1918 03 24

Calculating the number of days between 1900-01-01 and a date after 1918-03-24 using Joda-Time seems to give an off-by-one result. Using Java 8 java.time gives the correct result....
Jon Skeet
people
quotationmark

The problem is that your DateTimeFormatter is using the system default time zone. Ideally, you should parse to LocalDate values instead of DateTime, but you can fix it by using UTC for the formatter anyway: DateTimeFormatter dateDecoder =... more 10/10/2017 9:54:20 AM

people

java: timezone getTimeZone("GMT 0700")' timezone useDaylight incorrect

I want to get the time zone information for Los Angeles, now 10/10/2017 is daylight saving time, But I got a different result when I got the time zone in Los Angeles in two...
Jon Skeet
people
quotationmark

I want to get the time zone information for Los Angeles, now 10/10/2017 is daylight saving time So you should ask for the "America/Los_Angeles" zone. That's what it's there for. The "GMT-07:00" zone is a fixed-offset zone - it's only... more 10/10/2017 7:25:07 AM

people

C# ValueTuple properties naming

I'm trying ValueTuple Class in C#, and i have a doubt about properties naming, let's see: If instantiate a ValueTuple declaring the object like this: var tuple1 = (Name: "Name1",...
Jon Skeet
people
quotationmark

There are two different "kinds" of tuples involved here: the .NET ValueTuple<...> types, and C# tuple types. C# tuple types can have element names; ValueTuple<...> types can't. (There's simply nowhere in the type system for... more 10/6/2017 9:03:45 AM

people

ObjectOutputStream does not write objects when taking BufferedOutputStream

I've done my research but it seems I can't find enough documentation on the subject. When trying out some code on Object streams, I came to notice that putting a...
Jon Skeet
people
quotationmark

You're trying to create the ObjectInputStream on the same file that you're writing to - you never even get into the body of your try-with-resources block. Here's what happens: Create the FileOutputStream: file is empty Wrap it in... more 10/5/2017 2:56:56 PM

people

Object from class library not contains methods

Trying to build and use class library in C#. Creating class library: File-New Project-Windows-Classic Desktop-Class Library Code: namespace ClassLibrary2 { public class...
Jon Skeet
people
quotationmark

Add is a static method. You can't call static methods "via" instances in C#. That has nothing to do with it being in a different library. You can call the method as: long result = ClassLibrary2.Class1.Add(10, 20); or if you actually... more 10/5/2017 9:22:33 AM

people

DST changes caused an java.text.ParseException: Unparseable date

Following is the code snippet which is throwing an exception: SimpleDateformat dateFormatter = new SimpleDateFormat("yyyyMMddHHmm"); Date date =...
Jon Skeet
people
quotationmark

You're trying to parse a date/time that didn't occur. We now know that this was in the Sydney time zone. At 2am on October 1st 2017 in Sydney, the clocks went forward to 3am. If you were looking at a clock every minute you'd... more 10/5/2017 9:03:07 AM

people

Explicitly marking derived class as implementing interface of base class

interface IBase { string Name { get; } } class Base : IBase { public Base() => this.Name = "Base"; public string Name { get; } } class Derived : Base//, IBase { ...
Jon Skeet
people
quotationmark

It's explained in sections 13.4.4 to 13.4.6 of the C# 5 specification. The relevant sections are quoted below, but basically if you explicitly state that a class implements an interface, that triggers interface mapping again, so the... more 10/3/2017 9:41:51 AM

people

Why regex Matcher.find not showing a word which meets the criteria

The given regex code is import java.util.regex.*; public class Test { public static void main(String[] args) { String longString = " Derek Banas CA 12345 PA...
Jon Skeet
people
quotationmark

Your pattern includes whitespace after the non-whitespace. That accounts for both of your questions: the space between "Derek" and "Banas" counts as part of the first match, which stops it being part of a match for "Banas" (because you'd... more 10/1/2017 8:55:10 PM

people

Adding elements to different collections in a single lambda expression

I possibly use the wrong terms, feel free to correct. I have a test method which takes a Runnable: void expectRollback(Runnable r) { .. } I can call this method like...
Jon Skeet
people
quotationmark

It's subtle, but I think I've got it. In JLS 15.27.3 we have: A lambda expression is congruent with a function type if all of the following are true: ... If the lambda parameters are assumed to have the same types as the... more 10/1/2017 8:29:15 AM

people