Browsing 7239 questions and answers with Jon Skeet

Java 8 Lambda Expression

import java.util.function.Function; public class LambdaExpression { @SuppressWarnings("rawtypes") public static Function create(int addTo){ int n = 1; ...
Jon Skeet
people
quotationmark

If you want to create a function which adds 1 to its input, the method to create that function doesn't need an parameters... but then you need to call that function in order to execute it. I suspect you wanted: import... more 10/5/2015 4:32:23 PM

people

Reflection for Constructors

Here: defaultCon binds itself to Dog() Constructor legCon binds itself to Dog(int legs) Constructor Why do we specify new Type[0] in Line X even though there are no...
Jon Skeet
people
quotationmark

Why do we specify "new Type[0]" in Line X even though there are no parameters in Default Constructor To say that there are no parameters - so the array of parameter types is empty. Why do we specify "(new[] { typeof(int) })" in... more 10/5/2015 3:52:12 PM

people

Extra zero in final out put where does it come from?

I wrote this code to order any set of numbers from biggest to smallest, but for whatever reason, the output always has a zero at the end. My question is, where did it come from?...
Jon Skeet
people
quotationmark

You're inconsistent between whether you're trying to handle input + 1 or input elements. For example: int[] array = new int[input+1]; for (int i = 0; i <=input-1; i++) { Console.WriteLine("Please enter entry number " + counter); ... more 10/5/2015 3:48:45 PM

people

How to check if a StringComparison is case sensitive?

Given a StringComparison instance, how should I check if it is case sensitive? Should I compare it to all currently known case sensitive values in the enum? StringComparison sc...
Jon Skeet
people
quotationmark

Yes, for the enum form (StringComparison) that's fine. MS is incredibly unlikely to add another StringComparison value now, given that adding a value to an enum is effectively a breaking change. For a StringComparer, it's rather harder :( more 10/5/2015 3:42:10 PM

people

PHP date incrementing error

I am trying to create a calendar where the date increments and each date is clickable, which links to a search. The strange part is that the date stops at 25th October, and stops...
Jon Skeet
people
quotationmark

This is the problem: $date = date("d-m-Y", strtotime($date) + 86400); You appear to be relying on that to increment the date. Usually, that will be fine... but it isn't when we have a 25 hour day, due to daylight saving time changes. I... more 10/5/2015 3:10:17 PM

people

NAudio.dll signing with a strong key fails

Is there any copy of NAudio.dll and NAudio.WindowsMediaFormat.dll that is pre-signed with a .pfx key already? I can't seem to sign it myself. When I try to recompile the source...
Jon Skeet
people
quotationmark

Basically, using InternalsVisibleTo from a signed assembly requires the assembly it's trusting to be signed too. You need to sign both the test project and the production project... or (if you really must) ditch the tests, and remove the... more 10/5/2015 11:29:34 AM

people

why does the compiler doesn't give error while assigning long to float?

when i execute the below code, i expected it to get warning "can't convert from long to float" because the float is 32 bits and long is 64 bits in size. But looks like no...
Jon Skeet
people
quotationmark

The range of float is much larger than the range of long... there's an implicit conversion which may lose precision, but not magnitude. The same is true for long to double. From JLS 5.1.2: A widening primitive conversion from int to... more 10/5/2015 9:48:10 AM

people

Override equals method gives an error

I'm a computer engineering student and I've started Java one week ago. I've been studying these days generic types and I wanted to mix it with equals and Overriding, so I wrote a...
Jon Skeet
people
quotationmark

You're comparing Double values by reference equality. I suspect you want if (!other.puntoX.equals(this.puntoX)) etc. I'd actually write this code as: @Override public boolean equals(final Object obj) { if (obj == null ||... more 10/5/2015 8:44:24 AM

people

Why can't Unary Operators operate directly on values in Java?

Not that I want to, but I'm wondering why the unary operators don't work directly on values in Java? Why does result++; work if int result = 0; but result = 0++; not work? All I...
Jon Skeet
people
quotationmark

It's not that unary operators don't work - for example -(+(-5)) is fine. But ++ doesn't just compute a value - its purpose is to increment a variable. 0 isn't a variable. From JLS 15.14.2 (postfix increment operator++) The result of... more 10/4/2015 8:33:07 AM

people

How do I rewrite this line using method syntax?

I'm working with SMO and I have this line of code: var results = (from User user in database.Users where user.LoginType == LoginType.WindowsUser select new { user.Name,...
Jon Skeet
people
quotationmark

No, they're very slightly different. Because you've got an explicitly-typed range variable here: from User user in database.Users your query is equivalent to: var results = database.Users .Cast<User>(); ... more 10/4/2015 7:57:48 AM

people