Browsing 7239 questions and answers with Jon Skeet

Limits of static method references in Java 8

I'm trying to use method references to capture method invocations and am hitting some limitations. This works fine: <T> void capture(Function<T, ?> in) { } private...
Jon Skeet
people
quotationmark

There are two problems here: You're using Function, which has to return something. setBar doesn't return anything. Function only takes a single input, but you've got two inputs: the Foo you'd call setBar on, and the String argument you'd... more 5/21/2014 9:38:59 PM

people

Object values and local values in arithmetic

So I was trying to perform a simple arithmetic on values within and object 'currentUser' in my one 'pricingAction' class. The code should add the two volume values(doubles) and...
Jon Skeet
people
quotationmark

Let's simplify the code a little so it's easier to read: foo.setX(foo.getX() + foo.getY()); foo.setY(foo.getX() + foo.getY()); Now suppose we start with foo.X = 10, foo.Y = 20. The first statement will initially compute foo.X + foo.Y -... more 5/21/2014 7:59:32 PM

people

printing instance data using static properties

I've written some list of classes, here's the code I used to initialize class public class Album { static public int IDNumber { get; set; } static public...
Jon Skeet
people
quotationmark

All your properties are static - that means that they are related to the type rather than any one instance of the type. (It's not that the values are "shared by all instance" - it's that they're completely unrelated to any instance.) You... more 5/21/2014 7:51:18 PM

people

c# method name expected INotifypropertyChanged

I'm running into a problem. I'm a VB.net programmer and I'm trying to learn C#. On many VB projects that I have done I've always used a viewModelBase class where I can notify my...
Jon Skeet
people
quotationmark

It sounds like you're just missing the fact that indexer syntax in C# is [key]. I suspect you want: if (TypeDescriptor.GetProperties(this)[propertyName] == null) That's first calling the GetProperties method, to find the... more 5/21/2014 7:45:19 PM

people

Formatting a double value within the toString() method (with respect to the decimal)

This is a fairly simple question. I have a class of objects Item which constructs the objects declared in the TestItem class. The overridden toString() method utilises the...
Jon Skeet
people
quotationmark

You can use String.format to control the format in general. Unfortunately I can't see any way of combining that with a custom pattern directly, but you can compose them. For example: import java.math.*; import java.text.*; public class... more 5/21/2014 7:26:32 PM

people

Java get parent of parent

This is a very similar question to this one: How to get just the parent directory name of a specific file But there he wanted to get just the closest Parent directory, what I...
Jon Skeet
people
quotationmark

getParent() returns a String - you can't call getParent() on a String. Instead, you want getParentFile(): File grandparent = file.getParentFile().getParentFile(); more 5/21/2014 6:32:48 PM

people

Using Moq with overloaded method

Why doesn't my Moq Test resolve to the appropriate Method. Calling the Service in my Test: var service = new EmployeeService(mockScoreRep); Uses the following Method public...
Jon Skeet
people
quotationmark

I suspect the problem is that you want the mock object, not the wrapper: var service = new EmployeeService(mockScoreRep.Object); In other words, you want to pass an IRepository<Score> - not a... more 5/21/2014 5:43:38 PM

people

Type Class is a raw type. References to generic type Class<T> should be parameterized

Class activityItems work fine but i get warning "Type Class is a raw type. References to generic type Class should be parameterized". How to fix it ? Here is my code: public...
Jon Skeet
people
quotationmark

I think it may just be a case of changing this: Class activityItems = Class.forName("com.arbaz.hk." + item); to: Class<?> activityItems = Class.forName("com.arbaz.hk." + item); That way you're still not saying you know what the... more 5/21/2014 5:41:20 PM

people

Is it possible to make dateTime.ToString(...) return a different timezone offset?

My project is using PDFSharp to normalize creation dates in pdfs. The issue I'm having is that people in different timezones get different offset values than I do. The problem is...
Jon Skeet
people
quotationmark

No, basically zzz will always use the system default time zone. From the documentation: With DateTime values, the "zzz" custom format specifier represents the signed offset of the local operating system's time zone from UTC, measured... more 5/21/2014 5:17:05 PM

people

Comparison method violates its general contract, how to make it transitive?

I dont see how it is not transitive, please someone suggest me the right way. if both values are null I return 0, the two other statements are pretty obvious. Why i got...
Jon Skeet
people
quotationmark

Look at this code: if (compInt1 < compInt2) { return -1; } else if (compInt1 >= compInt2) { return 1; } else { return 0; } How do you expect that ever to return 0? What values of compInt1 and compInt2 would make both... more 5/21/2014 4:16:33 PM

people