Browsing 7239 questions and answers with Jon Skeet

The error in example of Java Specification?

There are two main kinds of primitive conversion: widening conversion; narrowing conversion. I'm reading about widening conversion in Java SE Specification and here I'm seeing...
Jon Skeet
people
quotationmark

Yes, the last line uses a narrowing conversion, which is why a cast is necessary. The example is used to demonstrate that the widening conversion on the middle line loses information, that's all: This program prints -46 thus indicating... more 6/30/2015 5:27:10 PM

people

C# binary serialization error

So here it goes, I have the following JSON string: {"sTest":"Hello","oTest":{"vTest":{},iTest:0.0}} And I have de-serialize it using Newtonsoft.JSON as the...
Jon Skeet
people
quotationmark

To use BinaryFormatter, you'll need to create serializable classes to match the data in your JSON. So for example: // I'm hoping the real names are rather more useful - or you could use // Json.NET attributes to perform... more 6/30/2015 4:25:18 PM

people

Overloading method on extended class

Simple question, strange result. I have two classes A and B: public class A { protected int num; public A(int n) { num = n; } public boolean f(A a) ...
Jon Skeet
people
quotationmark

Why does y1.f(y2) calls the f() method in A instead of in B? Because the compile-time type of y1 is A. Overloading is performed at compile-time... the execution-time type of the object you call the method on is only relevant for... more 6/30/2015 3:03:30 PM

people

Transform Entity with Linq to XML

Let's assume my example entity TeamPlayer looks like this: PlayerId PlayerName Team Position ---------------------------------------------- 1 Nobody ...
Jon Skeet
people
quotationmark

Ugly as that is, it doesn't sound too hard using string.Join to create the appropriate text contents. After fetching the relevant data - which I assume you know how to do - you could just use something like: var records = ...; // The... more 6/30/2015 2:51:10 PM

people

Unreachable code when overriding Object.Equals and implementing IEquatable<>?

I'm a litte bit confused right now. From my understanding the .NET runtime will pick the overloaded method that best suits the given parameter's type. So I would think, that in...
Jon Skeet
people
quotationmark

Is it correct, that the Equals(object obj) method below will never be called with an instance of type Entry? No. Consider: object entry1 = new Entry(...); object entry2 = new Entry(...); bool equal = entry1.Equals(entry2); The... more 6/30/2015 12:26:54 PM

people

c# using return attribute what it does?

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MyTest { class Program { static...
Jon Skeet
people
quotationmark

It's just an attribute, like any other - the usage of the attribute is up to whatever decides to use it. It's relatively rare to see attributes for return, but it's entirely legal, and it's just metadata which can be examined by... more 6/30/2015 6:25:48 AM

people

Coming across NoClassDefFoundError in java

I come across an error while running this in Java: // Test.java public class Test { public static void main(String [] args) throws IOException { String a = "123"; ...
Jon Skeet
people
quotationmark

The problem is that the compiler you're using is from Java 5 or later, so it's using StringBuilder instead of StringBuffer - but the execution environment you're using appears to be Java 1.4.2, which doesn't include StringBuilder. Note... more 6/30/2015 6:18:30 AM

people

Using DataContractJsonSerializer to create a Non XML Json file

I want to use the DataContractJsonSerializer to serialize to file in JsonFormat. The problem is that the WriteObjectmethod only has 3 options XmlWriter, XmlDictionaryWriter and...
Jon Skeet
people
quotationmark

Assuming you're just trying to write the text to a file, it's not clear why you're writing it to a MemoryStream first. You can just use: var js = new DataContractJsonSerializer(typeof(T), _knownTypes); using (var stream =... more 6/30/2015 6:14:39 AM

people

Using "super" keyword or using a superclass instance when calling superclass methods locally in a method from subclass?

Let say I have: class Superclass { //fields... methodA() {...} methodB() {...} ... } class Subclass extends Superclass { //fields... methodA() { // Here I...
Jon Skeet
people
quotationmark

It works both ways, but I want to know which is better to use. Well that entirely depends on what you're trying to achieve. If you want to create a new, entirely independent instance, do so. But it's more common that you want to use... more 6/30/2015 6:01:57 AM

people

Best way to Insert JSON data into MYSQL

I have a JSON data in a text file which contains pair of latitude and longitude,Now I want to store this data into MYSQL DB,How to go about & what's the best approach please...
Jon Skeet
people
quotationmark

Some comments have suggested leaving it in JSON format and storing it in a text column. I'd suggest that if you have control over your schema, you should store it in two NUMERIC fields - one for latitude, and one for longitude.... more 6/30/2015 5:44:27 AM

people