Browsing 7239 questions and answers with Jon Skeet

Improving encoding cycle

I have this object: Dictionary<byte, BitArray>() It's filled with values from a huffman tree. To encode each byte of the stream to the huffman binary value I do: // Bytes...
Jon Skeet
people
quotationmark

It sounds like you're performing string concatenation in a loop. That's a very inefficient way of building a new string. I suspect you want: var builder = new StringBuilder(); foreach (byte c in Bytes) { ... more 10/23/2015 2:49:28 PM

people

Action same as Func<TResult>?

I came across a situation where i need some knowledge. Below is the code: // A function to match the delegate public static int DoSomething() { Console.WriteLine("i am...
Jon Skeet
people
quotationmark

What i want to know is that why Action action = () => DoSomething(); is not a compile time error? It compiles because you've got a lambda expression that calls the method but ignores the result. You couldn't use a method group... more 10/22/2015 2:44:25 PM

people

Optimizing For Loop result?

I'm currently using this code to check if the DataReader has column existing: public static class DataRecordExtensions { public static bool HasColumn(this IDataRecord dr,...
Jon Skeet
people
quotationmark

The main problem would be in the calling code... but you can avoid calling the method more than once in total, by changing your method to create and return a HashSet<string>: public static class DataRecordExtensions { public... more 10/21/2015 5:54:50 AM

people

using a FUNC method (selector) to return a "light version" of my list

I have an enumerable list of client and want to return a light weight "version" of my client object : IEnumerable<Client> clientList = blablabla. (data is fetched...
Jon Skeet
people
quotationmark

The problem is that you're using an expression tree - which is used by IQueryable<T> (or rather, the extension methods in Queryable targeting IQueryable<T>). For Enumerable.Select, you want a delegate instead. Just change your... more 10/20/2015 7:58:22 PM

people

Java object equality

I have a four domain objects in my project. They have 3 common attributes namely id, name and age. public class Domain1 { private String id; private String name; ...
Jon Skeet
people
quotationmark

I would just try not to do this. The rules you've suggested violate the requirements of Object.equals, in particular: It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns... more 10/20/2015 4:42:20 PM

people

Java, How can I use .nextLine as an object reference

I want to use something I scanned as a reference to an object for a method in a different class. Basically scanner.nextLine().method(); but I get cannot find symbol no matter what...
Jon Skeet
people
quotationmark

You have at least three problems here. Firstly, if your fileArray is a List<Word>, you're trying to find a string (the return type of nextLine()) within a list of Word objects... that's never going to work. Secondly, you're trying... more 10/20/2015 6:08:43 AM

people

Invalid time zone region while calling AT TIME ZONE function in Oracle database

Just a simple question about the "AT TIME ZONE" function in Oracle. It seems the time zone named CEST is not a valid argument for this function despite the fact it is listed in...
Jon Skeet
people
quotationmark

AT TIME ZONE takes a time zone name - you're passing in the time zone abbreviation. The names are in the TZNAME column of the results you're showing us, but you're using the value from TZABBREV. Abbreviations are a bad idea... more 10/18/2015 12:15:59 PM

people

Instanceof syntax error?

I have an exercise which relates to "instanceof" and I am not quite sure how to use it. This is what I came up with: for(int i = 4; i < 6; i++){ int availSupply =...
Jon Skeet
people
quotationmark

You can't use instanceof with an expression of a primitive type, as you're doing here with availSupply. An int can't be anything else, after all. If getAvailForAssembly() is already declared to return int, then you don't need your if... more 10/17/2015 9:56:12 AM

people

Don't understand why I receive null

So here is my Superhero class: public class Superhero { public int strength; public int powerUp; public int defaultStrength = 10; public String name; public...
Jon Skeet
people
quotationmark

Look at your constructor: public Superhero(String name) { this.strength = 10; System.out.println("The Superheroes available are :" + name); } That sets the instance field strength, but doesn't do anything with the name instance... more 10/16/2015 4:51:18 PM

people

Encoding.Unicode.GetBytes c# to java

i need the same byte in Java Encoding.Unicode.GetBytes("asd") //{97, 0, 115, 0, 100, 0} C# "asd".getBytes() //{97, 115, 100} Java
Jon Skeet
people
quotationmark

You're calling getBytes in Java without passing any charset, so it's using the default one. You want something like: byte[] bytes = "asd".getBytes(StandardCharsets.UTF_16LE); more 10/16/2015 4:47:45 PM

people