I have a rest web service, and below is how i have declared DateFormat as this is the date format i am going to use application wide.
When i did code analysis using SonarLint eclipse plug-in, i got major warning saying "Make DATE_FORMAT as instance variable."
public class Constants {
private Constants() {
}
public static final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss:SSS");
}
Can anyone tell me what issue i might face if i use it this way in my rest API ?
If i use it as instance variable i will end up declaring it in multiple classes ?
Static variable are mostly used for Constants.
Here you have declared static and assigning it instance of SimpleDateFormat
.
Either make DATE_TIME_FORMAT
non-static or assign a constant to this variable.
Better change it to instance variable and use a Sting to do that.
e.g
public final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss:SSS";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With