Browsing 7239 questions and answers with Jon Skeet

Is there any way to convert ZoneId to ZoneOffset in java 8?

I have an epoch second and a zoneId,by method1.It can be convert to LocalDateTime with system default zoneId,but I don't find the way to convert epoch second to LocalDateTime by...
Jon Skeet
people
quotationmark

As the documentation says, "This is primarily intended for low-level conversions rather than general application usage." Going via Instant makes perfect sense to me - your epoch second is effectively a different representation of an... more 9/17/2015 9:29:31 AM

people

BufferOverflowException while converting int to byte

I have an counter which counts from 0 to 32767 At each step, I want to convert the counter (int) to an 2 byte array. I've tried this, but I got a BufferOverflowException ...
Jon Skeet
people
quotationmark

Yes, this is because an int takes 4 bytes in a buffer, regardless of the value. ByteBuffer.putInt is clear about both this and the exception: Writes four bytes containing the given int value, in the current byte order, into this... more 9/17/2015 9:17:50 AM

people

c# how can I read String of double correctly despite the number Format?

Hi guys my problem is this. I made a software in c# that is able to read and edit dxf files, I have to give this software to an american company but I have discovered the...
Jon Skeet
people
quotationmark

is there a way that make c# automatically recognised the "Culture" of the pc where is installed so that it can read the number correctly? That's what it's doing by default - and why you're having a problem, because the culture used to... more 9/17/2015 7:22:58 AM

people

How does this Java code snippet work? (String pool and reflection)

Java string pool coupled with reflection can produce some unimaginable result in Java: import java.lang.reflect.Field; class MessingWithString { public static void main...
Jon Skeet
people
quotationmark

What happened to Mario ?? You changed it, basically. Yes, with reflection you can violate the immutability of strings... and due to string interning, that means any use of "Mario" (other than in a larger string constant expression,... more 9/17/2015 6:34:28 AM

people

Inheriting the same method from multiple interfaces

That we know multiple (interface) inheritance is allow in c# but, I want to know is it possible that two interface Example : interface calc1 { int addsub(int a, int...
Jon Skeet
people
quotationmark

You can't overload the method like that, no - they have the same signatures. Your options are: Use one implementation, which will be called by both interfaces Use explicit interface implementation for one or both of the methods,... more 9/17/2015 6:10:12 AM

people

Calling a method to fill a 2d array in C#

I am a very new programmer, and have been struggling to write a method that can take any 2D array and fill it with random integers from 1 to 15. I believe I managed to...
Jon Skeet
people
quotationmark

Your method doesn't fill an array - it creates a new array. (It's also not at all clear what the parameters are meant to be for.) If you want it to fill an existing array, you should have that as the parameter: public static void... more 9/16/2015 8:56:52 PM

people

Linq equivalent for collection contains at least x items; like .Any() but instead .AtLeast(int)

Is there a Linq method to check whether a collection contains at least x items? .Any() is great because as soon as one item is found, it will be true and the program won't need to...
Jon Skeet
people
quotationmark

You can call Skip for the minimum number minus 1, and then check if there are any left: public static bool AtLeast(this IEnumerable<T> source, int minCount) { return source.Skip(minCount - 1).Any(); } Note that for large... more 9/16/2015 6:50:38 PM

people

How to use Linq to Xml with several levels in c#

So i've created a xml with several levels inside a "root" element. Basicly this is how it looks: <?xml version="1.0" encoding="utf-8"...
Jon Skeet
people
quotationmark

It sounds like you want something like: var fruit = collectXml .Descendants("Fruit") .Select(x => new Fruit { Col = (string) x.Element("Location").Element("Col"), Row = (string)... more 9/16/2015 5:05:09 PM

people

"? extends ParentClass" makes Read only?

In the following code Java, I have created a list nums. I can assign the another list during the declaration. But new items cannot be added except the null. So, does it mean the...
Jon Skeet
people
quotationmark

Is it possible to add new items in that list? Nope... because that code doesn't know what it's "actually" a list of. Imagine if you could: List<String> strings = new ArrayList<>(); List<? extends Object> objects =... more 9/16/2015 4:57:17 PM

people

Can the type of the current class be used as the value of a generic type parameter?

Can something like this be accomplished using C#? public abstract class BaseClass { public abstract IInterface<T> CreateEditor() where T:...
Jon Skeet
people
quotationmark

No, you can't do that - partly because it wouldn't make sense at compile time. Consider a slight change to your code: BaseClass instance = new DerivedClass(); var editor = instance.CreateEditor(); What could the compiler infer the type... more 9/16/2015 8:32:42 AM

people