Browsing 7239 questions and answers with Jon Skeet

`Fault` keyword in try block

While exploring an assembly in reflector I stumbled upon a fault keyword in a compiler generated class. Do any of you know the meaning if this keyword? C# private bool...
Jon Skeet
people
quotationmark

Do any of you know the meaning if this keyword? Yes. It's not valid C#, but in IL it's the equivalent of finally, but only if an exception has been thrown. There's no direct correlation in C#, which is why the decompiler can't... more 2/27/2014 10:08:08 AM

people

Casting error in BST iterator

I'm having trouble with casting for generics. What I'm trying to do is use a generic iterator to help me print out what is in my Binary Search Tree. However the for loop I'm...
Jon Skeet
people
quotationmark

The problem is your BinarySearchTree declaration. It's implementing the raw Iterable type, when it should be implementing Iterable<AnyType>. With the raw Iterator type, the code using the enhanced-for loop only knows that the values... more 2/27/2014 7:24:59 AM

people

Getting actual type from an exception thrown in base class

I have a series of classes in my application set up like follows: abstract class Foo<TYPE> where TYPE : new() { public void Error() { List<TYPE> foo...
Jon Skeet
people
quotationmark

You can't, just from an exception you don't control. There's no indication in the exception what instance happened to have a method executing when the exception was generated. I would suggest using a debugger (so that you can break if... more 2/26/2014 9:29:14 PM

people

Grey zone of DST

does anybody knows how to handle grey zones of DST (when time doesn't exist): e.g.: DateTime dt = new DateTime(2014,3,30,2,30,0); TimeZoneInfo tziSV =...
Jon Skeet
people
quotationmark

Use Noda Time :) That doesn't relieve you from the burden of thinking how you want to handle this - but it allows you to specify how you want to handle it. Fundamentally, you've been given a value that doesn't exist... so you can choose... more 2/26/2014 8:32:37 PM

people

issue with date and time zone how to get date without time zone?

I tried to do convert between date in Tics to UTC date time format - 'YYYY-MM-DDThh:mm:ss' public static DateFormat getFormat() { String systemLocale =...
Jon Skeet
people
quotationmark

It's not entirely clear what you're asking, but if all you want is to make your DateFormat use UTC, that's easy: public static DateFormat getFormat() { String systemLocale = System.getProperty("user.language"); //$NON-NLS-1$ ... more 2/26/2014 8:25:05 PM

people

Trouble with Map iterate

I want to iterate Map, where the value is another Map. I have this method: public void test(){ Map<Integer, Double> map1 = new HashMap<Integer, Double>(); ...
Jon Skeet
people
quotationmark

What's the problem? You've put the same value in the "outer" map for both entries: a reference to the single Map<Integer, Double> you've created. When you call put, it just adds the reference to the map - it doesn't take a deep... more 2/26/2014 7:24:25 PM

people

The constructor InputStreamReader(File) is undefined

import java.io.*; public class Streams { public static void main(String[] args) { File homedir = new File(System.getProperty("user.home")); File is = new...
Jon Skeet
people
quotationmark

Yes, it's quite right. Look at the documentation for InputStreamReader and you won't find a constructor taking a File parameter. Instead, you should construct a FileInputStream to read from the file, and pass that to the constructor of... more 2/26/2014 1:04:41 PM

people

java Reflect Modifiers parameters

I declared a simple class with this method amongst others : public void setDate(final Date date); when i get the parameters : List<Class<?>> params = new...
Jon Skeet
people
quotationmark

You're asking whether the type is final, not the parameter - and java.util.Date isn't a final class. Looking at the API, I can't immediately see any way of determining that a parameter is final - but that's really an implementation detail... more 2/26/2014 12:52:27 PM

people

Why is char '\"' same as char '"'?

quick question. Why are both lines below valid? char x = '\"'; char y = '"'; If " is a special character, shouldn't the second line be marked as incorrect?
Jon Skeet
people
quotationmark

If " is a special character, shouldn't the second line be marked as incorrect? No, because the rules of the language don't require " to be escaped within a character literal, only within a string literal. It's consistent to allow it... more 2/26/2014 11:09:32 AM

people

Is there a faster alternative to Array.Exists for huge sorted int arrays?

I am having two sorted int Arrays (both one-dimensional, Array1 could have up to several million entries, Array2 will probably be a lot smaller, I am thinking six figures, no...
Jon Skeet
people
quotationmark

If it's sorted, you can use Array.BinarySearch which will be O(log n) instead of O(n): int index = Array.BinarySearch(sortedArray, targetValue); if (index >= 0) { // Found! } (BinarySearch returns a negative number if the value... more 2/26/2014 10:42:00 AM

people