Browsing 7239 questions and answers with Jon Skeet

Is it OK not to call close method?

Below code is the serialize method of org.springframework.util.SerializationUtils(spring-core.3.2.1.jar). As you can see, there is no oos.close method. Is it OK not to call close...
Jon Skeet
people
quotationmark

In this particular case, it's okay - the two streams involved (the ObjectOutputStream and ByteArrayOutputStream) don't use any unmanaged resources (file handles, network handles) etc so it's okay for the garbage collector to just take care... more 6/30/2014 2:31:21 PM

people

Using Group By Having in Lambda expression

Can anyone help me to convert the below query to LINQ with Lambda expression. select idshiftschedule,Date from Teammateassignments where IdClinic = 19 group by...
Jon Skeet
people
quotationmark

That's just a filter on the groups afterwards: var results = from item in assignments where item.IdClient == 19 group item by new { item.IdShiftSchedule, item.Date } into g where g.Count()... more 6/30/2014 12:50:01 PM

people

Why private static field = new Singleton is not lazy in Java?

I read a lot of articles about Singleton, in most of which authors said that this variation of Singleton in Java: public class Singleton { private static Singleton instance =...
Jon Skeet
people
quotationmark

Basically it's a matter of degrees of laziness. It's lazy in that it won't construct the singleton until the class is initialized, but it's eager in that there could be situations where you want to use the class without initializing the... more 6/30/2014 9:45:42 AM

people

HashMap Object reference confusion

Hello I'll go straight into the problem. I know that in HashMaps in java the valueSet stores REFERENCE, that means that if I change that reference the specific value of that key...
Jon Skeet
people
quotationmark

I changed the value of String s Yes, you changed the value of s. That's all you changed. The map still contains the previous value of the variable. You haven't changed the meaning of that value. We can simplify your example to just... more 6/30/2014 8:57:20 AM

people

Why the Garbled Output when Replacing /* Comments?

I want to replace /* in selected text with //. I used regex to do this. When I used any other strings it worked. But when I used: String result =...
Jon Skeet
people
quotationmark

* has a special meaning in regular expressions - it means "match 0 or more of the preceding character/group". It sounds like you don't want a regex at all - you just want string result = seltext.Replace("/*", "//"); If you really want... more 6/30/2014 6:00:30 AM

people

Does MSbuild require Visual Studio to be installed on the build server?

Can we use MSBuild without Visual Studio 2012? Currently, we have a build server where we are compiling and creating deployment copy of one of our projects, it has Visual Studio...
Jon Skeet
people
quotationmark

No, you don't need Visual Studio on your build box. If I recall correctly, msbuild is installed as part of the .NET framework - it certainly used to be. Depending on what you're building, you may find that there are some things which are... more 6/30/2014 5:54:49 AM

people

Loading images into an array in Java

I am trying to load some images into an array for an applet and I know there has to be a better way to do this? public class Images extends Applet { Image card[]=new...
Jon Skeet
people
quotationmark

Even if the filenames aren't predictable based on number, you could still have a collection of them. For example: // Common prefix removed for brevity private static final String[] IMAGE_FILES = { "img1.gif", "happy.gif", "sad.gif" /*... more 6/30/2014 5:50:42 AM

people

IllegalMonitorStateException calling wait() on a thread inside its run method (with no synchronized block)

I order to ensure that the thread which is reading data from a socket is stopped when the socket closes (due to the fact socket.isClosed() doesn't work as expected) I wrote a...
Jon Skeet
people
quotationmark

Can anybody tell me what I am doing wrong here? Yes - you're not synchronizing on the object you're waiting on. The API documentation is pretty clear: Throws: IllegalMonitorStateException - if the current thread is not the owner... more 6/29/2014 6:53:27 PM

people

Reading Objects From A File to An Input Stream

I am presently working on a simple ObjectInputStream and ObjectOutputStream, I have read both the documentation and the Java tutorial and am familiar with the basics; however, in...
Jon Skeet
people
quotationmark

It sounds like you originally just wrote the Product objects to an ObjectOutputStream, rather than a Map<Integer, Product>. If that's the case, you need something like: Map<Integer, Product> products = new... more 6/29/2014 6:46:52 PM

people

Best practice to handle an impossible value for a static variable in Java?

(This question isn't about how it can be done, but rather how it should be done.) I'm implementing a program that creates a decision tree. There are different ways the tree can...
Jon Skeet
people
quotationmark

Throw an exception and don't catch it. Let it propagate all the way up. If something you consider to be impossible has happened, then you should have no confidence at all in your ability to "handle" it... the world is hugely screwed... more 6/28/2014 8:25:35 PM

people