-
ALM: gerrit (LF/ONAP)
-
CI: jenkins
-
Languages of the repository: java
-
https://sonarcloud.io/project/issues?id=onap_policy-apex-pdp
-
Error observed
Given a method with a parameterized return type, e.g.:
public <T> T getValue() { ... }
Sonar reports S6212, “use ‘var’” for the following:
MyType result = getValue();
Unfortunately, if “MyType” is replaced with “var”, then the java compiler doesn’t know the type of “result” and just assumes that it’s a plain Object, which is not typically correct.
- Potential workaround
It’s messier, but the following can be used instead:
var result = (MyType) result;