I want to make a defensive copy of a collection passed into a method using Guava’s immutable types, e.g. an ImmutableList. I must also be able to deal with null input and treat that like an empty …
Tag: coding-style
Is it okay to declare Spring MVC response DTOs as static nested classes?
Sometimes it is very convenient to use Spring MVC automatic object-JSON conversion feature when you are designing RESTful API for your web application. For this feature to work, one needs to define a …
Rearrange modifier keywords in IntelliJ
Is there any way to automatically rearrange modifier keywords in IntelliJ? For example, if I have the following code: Rearrange it to: Answer Go to Settings and enable the Editor | Inspections | Java | Code style issues | Missorted modifiers inspection. It has a quick fix to sort the modifiers. This inspectio…
What is an acceptable way to format a long method call in Java? [closed]
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago. Improve this question Is it good style to write: (which is obviously far to long for one li…
HP Fortify SQL injection issue on preparedStatement in java
I am using HP Fortify to measure code quality of my java code. HP Fortify is reporting SQL Injection error on so how to resolve this? Answer From my experience, HP Fortify will report an error on this scenario if it cannot trace the origin of all the Strings you are using to build your queryString to constant…
In Intellij, how do I toggle between camel case and underscore spaced?
At my company we have two different style guides for java vs sql. In java I have a field named historyOfPresentIllness and when i write the sql, I want to name it history_of_present_illness. Is there a keyboard shortcut to switch from one to the other when I have the phrase highlighted? Or perhaps a plugin th…
What is the criteria to choose between valueOf() and newInstance()?
Suppose I have a class ObjectInfo which contains Object name & Object type as String.(I am just cooking up something for the sake of asking the question.) And If I want to provide a static factory method to creating instances of this class, which of the following two methods is better & why? Basically…
Is it bad practice to separate sections of code inside one method with curly brackets? [closed]
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 1 year ago. Improve this question I tend put multiple lines of code that fullfill a certain task into bl…
Coding Conventions – Naming Enums
Is there a convention for naming enumerations in Java? My preference is that an enum is a type. So, for instance, you have an enum I am opposed to naming it: I understand it is easy to pick off which files are enums, but then you would also have: Also, is there a good document describing the same for constant…