Browsing 7239 questions and answers with Jon Skeet

Same Serial version id for all the classes?

Java specification stats that The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during ...
Jon Skeet
people
quotationmark

I believe the serialVersionUID is only used to determine the version of that class that has been serialized - the class name is always present too, so it won't lead to any ambiguity. Please let me know what is the use of putting same... more 9/25/2014 6:04:03 PM

people

Accessing own private fields of subclass object

Just found this construction does not compile: class A { private int data; public static int process(B b) { return b.data;// error here: 'data has private access...
Jon Skeet
people
quotationmark

Well, the compiler doesn't allow it because the language specification doesn't allow it. JLS section 8.3 (field declarations) specifies (emphasis mine): A class inherits from its direct superclass and direct superinterfaces all the... more 9/25/2014 4:54:07 PM

people

java enums cannot convert from MyClass.Result to int

I have issues storing an enum value and then querying it via the toString() method. I require to handcode the numbers. How do I safely override my toString() ? public enum Result...
Jon Skeet
people
quotationmark

Others have explained why your switch statement is failing - and unless you need the numbers for some other reason, you can get rid of them. But you don't need the switch statement at all - just make the message an instance... more 9/25/2014 4:41:45 PM

people

Linq query on Xdocument returns "System.linq.Enumerable+WhereSelectEnumerableIterator'2[system.XML.Linq.Xelement,System.String]

I'm using the following XML: <?xml version="1.0" encoding="windows-1252"?> <hexML> <head> <title><![CDATA[...
Jon Skeet
people
quotationmark

Yes, that's because you've calling ToString() directly on a query for your second and third values - whereas in the first operation, you're calling Single() which will return a single string value. Basically, don't call ToString() on... more 9/25/2014 4:26:55 PM

people

Stacktrace shows funcion call that is not directly present in failing method

I have a website used by several person and only one person experiences a bug with a strange stacktrace : System.FormatException: String was not recognized as a valid...
Jon Skeet
people
quotationmark

I suspect that: The reason for the problem is due to some broken culture-specific settings on the one person's machine, e.g. a culture which uses an invalid DateTimeFormatInfo.ShortDatePattern The reason the direct stack frame isn't... more 9/25/2014 3:00:50 PM

people

TryGetValue pass uninititialized value OK?

Take the following code for exhibit A: string sql; if (!GetQueries.TryGetValue(type.TypeHandle, out sql)) Documentation for Dictionary says that if the Key isn't found, the...
Jon Skeet
people
quotationmark

In my view, it's better not to set it to a value. After all, that value is guaranteed to be replaced by the method call (assuming that doesn't throw an exception) so why bother specifying a value which is pointless? It just misleads the... more 9/25/2014 1:48:17 PM

people

StreamWriter writing a text file's content incorrectly

I am using the StreamWriter class to write some text to a newly created text file, but the output is always weirdly wrong, this is my code: StreamWriter sw = new...
Jon Skeet
people
quotationmark

The problem is that this expression: d + '^' doesn't involve any strings. It's trying to add an int and a char, which it does by promoting the char to int (which will have a value of 65342, because that's the UTF-16 code unit for '^'),... more 9/25/2014 1:46:01 PM

people

Convert from hex64 to base 64 String

My input hex is C30A010000003602000F73B32F9ECA00E9F2F2E9 I need to convert it to the following base 64 encoded String: wwoBAAAANgIAD3OzL57KAOny8uk= I can simulate this...
Jon Skeet
people
quotationmark

Basically, hexString.getBytes() doesn't do what you expect it to. It's just encoding the string as a byte sequence in your platform default encoding - it's got nothing to do with hex. You need to decode from hex to byte[] to start with.... more 9/25/2014 1:17:11 PM

people

Creating table dynamically by SQL in Servlet

I am getting error in this: prepared statement. Prepared Statement: PreparedStatement pStatement=connection.prepareStatement ("CREATE TABLE `details`.?(`ID` VARCHAR(255) NOT...
Jon Skeet
people
quotationmark

JDBC parameters aren't usually usable for table and column names - they're only for values. Unfortunately, I think this is one of those cases where you will need to be build the SQL dynamically. You will want to be very careful about... more 9/25/2014 11:50:54 AM

people

Can't loop children of returned XML Nodes in C#

I have a large, messy XML file and I want to retrieve ALL elements of the same name ("Item" for the sake of this post) from it, then be able to retrieve data from each element's...
Jon Skeet
people
quotationmark

This is the problem: .Select(d => d.Name) You're explicitly selecting the names of the elements. If you want the actual elements (which I think you do), just get rid of that call: var nodes = doc.Descendants().Elements(ns +... more 9/25/2014 11:44:47 AM

people