Could you please explain your reasoning behind java:S6212 and why this is now considered a codesmell?
The jira ticket and the descriptions are vague
I do not believe that this is a code smell and it is more a matter of preference. In my case, I prefer and will continue to use the type explicitly
From the style guide : Local Variable Type Inference: Style Guidelines
varfor declarations can improve code by reducing clutter, thereby letting more important information stand out. On the other hand, applying
varindiscriminately can make things worse. Used properly,
varcan help improve good code, making it shorter and clearer without compromising understandability.
It seems that this continues to be controversial. I wonder why you decided to take a drastic stand that this is a codesmell. Also, it seems that a good variable name needs to accompany the usage of var, otherwise, it will be more confusing that the alternative. For example, see :
String category = relationshipJson.getJsonObject(JSON_KEY_ACCOUNT) var category = relationshipJson.getJsonObject(JSON_KEY_ACCOUNT)
Which one do you think that is more clear from this code? In my opinion, the one with the type is but sonar considers this a codemell and recommends it to be replaced with var
At the same time, it is true that sometimes it could help :
B2B2CNetwork b2b2cNetwork = new B2B2CNetwork(); var b2b2cNetwork = new B2B2CNetwork();
But again, it is very controversial and depends on the context. Adding this as a blanket codesmell is bad in my opinion