Browsing 7239 questions and answers with Jon Skeet

How does Servlet HttpServletResponse::setCharacterEncoding() work?

I have learned that in general, Java uses UTF-16 as the internal String representation. My question is what actually happens when composing a response in Java and applying...
Jon Skeet
people
quotationmark

I'm assuming you're talking about a class that works along the lines of HttpServletResponse. If that's the case, then yes, it changes the body of the response, if you call getWriter. The writer that is returned by that has to convert any... more 7/31/2016 8:38:52 AM

people

C# const string dictionary

In the information system that i am working with (SAP Business One), every document is represented in a SQL table. for example: Client order document : ORDR Invoice document :...
Jon Skeet
people
quotationmark

Ideally you shouldn't be doing string replacement with the generated string - instead, generate it from the translated strings. So for example - without knowing what code you've actually got - you could have: private static readonly... more 7/31/2016 8:27:41 AM

people

C# transform an async task from one type to another

I'm used to working with the Scala programming language - using Scala I could map over futures, such as: val response: Future[HttpResponse] =...
Jon Skeet
people
quotationmark

I'm slightly surprised there isn't anything in the framework for this, to be honest. (More likely, there is an I haven't seen it.) You can build it fairly easily though: public static async Task<TResult> Map<TSource, TResult> ... more 7/29/2016 2:01:22 PM

people

The prefix "beans" for element "beans:beans" is not bound

I am trying to add CSS and JS to JSP page in a spring MVC project so that I have included the reference of js/css folder in dispatcher-servlet.xml as below: <?xml ...
Jon Skeet
people
quotationmark

Look at your root element declaration - you've specified namespaces for the prefixes mvc, xsi, context, p, and tx, but nothing for beans. You've made "http://www.springframework.org/schema/beans" the default namespace, but you haven't... more 7/29/2016 10:35:34 AM

people

Java null arguments when chaining Constructors

Let's say I have a class with multiple constructors, one of which is a copy-constructor (to copy an object): public class Rectangle { int width, height; public...
Jon Skeet
people
quotationmark

Yes, you can use a helper method which will throw the exception if necessary, and return the original value otherwise... you can call that within your constructor invocation, as you're allow method calls as part of argument evaluation. //... more 7/29/2016 9:46:33 AM

people

Copy a Nullable property to a non Nullable version using Reflection

I am writing code to transform one object to another using reflection... It's in progress but I think it would boil down to the following where we trust both properties have the...
Jon Skeet
people
quotationmark

Given that GetValue returns a boxed representation, which will be a null reference for a null value of the nullable type, it's easy to detect and then handle however you want: private void CopyPropertyValue( object source, string... more 7/28/2016 1:50:54 PM

people

converting Japanese characters to hex not working

My code is very simple (using commons-codec-1.10.jar) System.out.println(Hex.encodeHex("三菱グループ".getBytes(StandardCharsets.UTF_8), true)); it yields...
Jon Skeet
people
quotationmark

Hex.encodeHex is working fine, but the results are the UTF-8 encoding, whereas codebeautify.org appears to be using UTF-16. Let's take 三 to start with. That's U+4E09. In UTF-16 that's encoded as 4E 09, which matches the start of your... more 7/28/2016 11:17:56 AM

people

Should I use nested blocks to improve performance

I have been learning about stack and heap and particularly the stack with its LIFO approach. Does this work with nested blocks within methods and can this be used to improve...
Jon Skeet
people
quotationmark

The stack is allocated for the whole of the method call anyway. There are some subtle cases where adding extra blocks could help, in terms of captured variables - if you have two lambda expressions, one of which captures i and one of... more 7/28/2016 10:28:47 AM

people

What does git H do?

I am working with this command: sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production and I am the root user so I should be able to also use the command...
Jon Skeet
people
quotationmark

It's not git -H, it's an option to sudo. Read this as: sudo // This is what we're running -u git // Run the command specified later as user "git" -H bundle // Set the HOME environment variable to that of user... more 7/28/2016 8:51:43 AM

people

Why System.out.println prints the elements of an arraylist and not the hashcode of the object?

I didn't override toString() so I am confused. Isn't an ArrayList an object like arrays since they are created using new? Example: ArrayList <String> arri= new...
Jon Skeet
people
quotationmark

You don't have to override toString()... the object you're calling it on does. You're calling toString() on an ArrayList, and ArrayList overrides toString... or rather, AbstractCollection does, and ArrayList inherits the implementation: ... more 7/28/2016 7:13:54 AM

people