Browsing 7239 questions and answers with Jon Skeet

When Java's Garbage collector reclaims memory?

I know that Arrays of primitive type are implicitly initialized to 0 in java. So if I have a code : public class Foo{ public static void main(String args[]){ int[]...
Jon Skeet
people
quotationmark

I want to know if memory from arr[30] to arr[49] would already have been reclaimed by garbage collector at the line which has the comment? No, absolutely not. The array is a single object. It's either reachable, or it's not... more 7/15/2016 8:23:36 AM

people

Why is the ArrayStoreException a RuntimeException?

Let's say we have the following program: class Fruit {} class Apple extends Fruit {} class Jonathan extends Apple {} class Orange extends Fruit {} public class Main { ...
Jon Skeet
people
quotationmark

If the array remembers what type of data it contains, it means that it KNEW the type of data it contains. At execution time, yes... just like at execution time, the type of an object is known: Object x = "foo"; // The compiler won't... more 7/15/2016 8:20:14 AM

people

.net core: Why dotnet restore generates a "lock" file, what's the usage of it?

I am new to dot.net core and tried the sample, dotnet new, dotnet restore, dotnet run. After 2nd step(dotnet restore), I tried to delete this lock file, then "dotnet run" fails,...
Jon Skeet
people
quotationmark

If you look at the lock file, you'll see that it contains details of the exact version of each dependency that was restored, transitively. This "locks" that set of versions until dotnet restore is run again. I believe the aim at least was... more 7/15/2016 7:48:20 AM

people

Need to convert a byte array to a transmittable String and back again (This isn't a duplicate)

Ok so I know this gets asked a decent amount, but this is slightly different. I have a program that takes an image file (or any input file of the user's choosing) and converts it...
Jon Skeet
people
quotationmark

However, when converting the String array (each element containing one byte) back into a byte array, it tells me that I can't convert a String (or Integer when I tried Integer.parseInt) into a byte object. Any idea what's... more 7/15/2016 2:05:24 AM

people

Enum.TryParse and Enum.IsDefined returns false for char Enums

I have my program as below: using System; namespace Rextester { public class Program { public static void Main(string[] args) { char _status...
Jon Skeet
people
quotationmark

Yes, that's because your enum is effectively: public enum MyStatus { None = 78, Done = 67 } So "N" is neither the name of an enum value, nor is it the decimal representation. Both "None" and "78" would parse to MyStatus.None,... more 7/14/2016 4:57:11 PM

people

java jar writes in two different character encoding

So my code is working fine when running from Eclipse, but executing the project's runnable jar does not. Here is my code: import java.io.BufferedReader; import...
Jon Skeet
people
quotationmark

Well that just sounds like you're getting different default encodings when running in different ways - which is somewhat to be expected. Just specify the encoding when you convert the text to binary: byte[] bytes =... more 7/14/2016 6:11:30 AM

people

java serialization random access, a very strange thingļ¼

I plan to use ByteArrayOutputStream to write Objects to byte array, then write the byte array to a file. I keep the position of each Object. Then I read from the file, using...
Jon Skeet
people
quotationmark

I suspect that ObjectInputStream simply isn't designed for this sort of use. In order to maintain referential integrity, I suspect there's an internal counter for "object number X that I've written to the stream" which is increased as... more 7/13/2016 12:56:28 PM

people

Why does Google.Pubsub.V1 beta01 not work with dotnet cli projects?

I have created a very simple program which should list the topics available in a Google Cloud project. The code is trivial: using System; using Google.Pubsub.V1; public class...
Jon Skeet
people
quotationmark

This is currently a limitation in gRPC 0.15, which Google.Pubsub.V1 uses as its RPC transport. Under msbuild, the build/net45/Grpc.Core.targets file in the Grpc.Core package copies all the native binaries into place. Under DNX, the... more 7/13/2016 10:34:21 AM

people

How to deal with two libraries that need different versions of an assembly?

I have a C# ASP.NET site that uses a 3rd party library with a dependency on JSON.NET. It pulls in [Newtonsoft.Json, Version=4.0.5.0] as part of its reference. Yesterday, I added...
Jon Skeet
people
quotationmark

You need an assembly binding redirect. For example, in your web.config file: <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity... more 7/13/2016 9:31:18 AM

people

Why is it the the following does not print true for the objects created using an object that was just set to null?

I am currently in the process of obtaining my Oracle certification and this is one of the concepts that I am failing to grasp. The following code snippet does not print true even...
Jon Skeet
people
quotationmark

b was created using a and a has now been set to null. You've misunderstood what this line does: B b =(B)a; That copies the current value of a as the initial value of b. That's all it does. The two variables are then entirely... more 7/13/2016 8:15:10 AM

people