Browsing 7239 questions and answers with Jon Skeet

Class derived from generic class don't get the correct type

In my spring project, I have this template for my Dao classes: public class Dao<E> { private final E entity; @Autowired SessionFactory sessionFactory; ...
Jon Skeet
people
quotationmark

I strongly suspect that this is the problem: public Dao(Class<?> classe) { this.entity = (E) classe; } You're effectively casting Usuario.class to Usuario. That's not right. The class and an instance of the class are different... more 5/20/2014 11:55:22 AM

people

Unable to call extension method with null object

I'm trying to parse XML attributes out of a XmlDocument. Since it's possible, that a certain node does not have a specific attribute, I've created an extension method to check the...
Jon Skeet
people
quotationmark

I suspect the problem is that if Attributes["SomeAttribute"] return null - so finding the Value property will fail. If column is an XmlElement, that would certainly be the case - look at the XmlAttributeCollection.ItemOf(string) property... more 5/20/2014 6:16:49 AM

people

C# windows 8 apps. Shrinking code

I have here a bunch of codes that is likely similar but only differs in some static( the names). public void Windows() { var win = new ListViewItem { Content = "Windows"...
Jon Skeet
people
quotationmark

Just pass in the delegate you want to use to subscribe to the event, as well: // I can't find the docs for ListViewItem.Tapped right now - adjust the // type of the "handler" parameter to match the event public void CreateItem(string... more 5/20/2014 6:11:22 AM

people

Generic types comparison

I have two objects of generic type T. T x , T y I want to be able to do comparison like: if (x >= y) Therefore I try to use the compareTo method which is missing until...
Jon Skeet
people
quotationmark

Not sure why only then I see it and not before writing it. Because until that constraint exists, the compiler has no idea what members are available on T, other than those which are present as part of object. You wouldn't expect to be... more 5/19/2014 5:02:48 PM

people

Unable update file store in appdata scope 500 Internal Server Error

Previously, I have a set of Google Drive API code, which works fine in the following scenarios Save new file to appdata Update previous file in appdata Save new file to...
Jon Skeet
people
quotationmark

Note: please do not treat this as an "official answer from Google". Although I work at Google, I don't work on the Drive API. I've reproduced the problem, and reported it to the Drive API team, who may be able to provide more details. In... more 5/19/2014 4:13:55 PM

people

How to send array byte of a pdf file via soapUI

I'm testing a wsdl file via SoapUI and want to send byte[] of a pdf file to client. byte[] are received at client side, but the created pdf file is blank. Below is what I have...
Jon Skeet
people
quotationmark

This is the problem - or at least a problem: new File(groovyUtils.projectPath + "//file1.pdf").text You're loading a binary file as if it's text. It's not. Don't read it as text and then convert it to byte - use byte[] pdfBytes = new... more 5/19/2014 3:01:46 PM

people

confused by C# type conversion

I'm new to C# but familiar with vb.net my setVendor functions expects an int and a string why does this work shopify.setVendor(System.Convert.ToInt32(reader["ProductID"]),...
Jon Skeet
people
quotationmark

There's an overload of Convert.ToInt32 which accepts object. There's no such overload for int.Parse. The argument must be a string at compile time. You would need: shopify.setVendor(int.Parse(reader["ProductID"].ToString()), ... more 5/19/2014 2:03:15 PM

people

Java Array references

I need to find another way to comunicate the more populated city of an array. The code is like this but sometimes he give me the right city name, and sonetimes he give me the...
Jon Skeet
people
quotationmark

The most immediate problem is here: if (total > higher) { higher = total; c++; } By incrementing c you're just remembering how many cities had a larger population than any of the preceding ones. You want to remember the index... more 5/19/2014 1:32:57 PM

people

alternative of list.FindIndex(x => x.UpperLimit >=lInput && x.LowerLimit <= lInput); in .net 2.0 framework

I realized lamba is not supported by .net 2.0; would like to know the alternative of following statement in .net 2.0 list.FindIndex(x = x.UpperLimit = dblInput &&...
Jon Skeet
people
quotationmark

I realized lamba is not supported by .net 2.0 That's not true. You can use lambda expressions to create delegates in .NET 2.0 with no problem. You need a C# 3 compiler (or later), that's all - it's a compile-time transformation which... more 5/19/2014 12:30:15 PM

people

Lambdas in C# Capturing Outer Variables Pls explain example from book "C# in nutshell 5.0"

What difference between static Func<int> Natural() { int seed = 0; return () => seed++; // Returns a closure } and static Func<int> Natural() { ...
Jon Skeet
people
quotationmark

The difference is that in the first version, you're declaring a variable and then capturing the variable in the lambda expression. The variable itself "survives" across multiple invocations of the delegate. In the second example, you're... more 5/19/2014 12:19:55 PM

people