app/src/main/java/com/mizo0203/natureremoapisample/data/source/NatureRemoLocalApiClient.java
T is not used in the method. Open
Open
private <T> Callback<T> createCallback(final NatureRemoRepository.Callback<T> callback) {
- Read upRead up
- Exclude checks
Type parameters that aren't used are dead code, which can only distract and possibly confuse developers during maintenance. Therefore, unused type parameters should be removed.
Noncompliant Code Example
int <T> Add(int a, int b) // Noncompliant; <T> is ignored { return a + b; }
Compliant Solution
int Add(int a, int b) { return a + b; }
Move the contents of this initializer to a standard constructor or to field initializers. Open
Open
{
- Read upRead up
- Exclude checks
Non-static initializers are rarely used, and can be confusing for most developers because they only run when new class instances are created. When possible, non-static initializers should be refactored into standard constructors or field initializers.
Noncompliant Code Example
class MyClass { private static final Map<String, String> MY_MAP = new HashMap<String, String>() { // Noncompliant - HashMap should be extended only to add behavior, not for initialization { put("a", "b"); } }; }
Compliant Solution
class MyClass { private static final Map<String, String> MY_MAP = new HashMap<String, String>(); static { MY_MAP.put("a", "b"); } }
or using Java 9 Map.of
:
class MyClass { // Compliant private static final Map<String, String> MY_MAP = java.util.Map.of("a", "b"); }
or using Guava:
class MyClass { // Compliant private static final Map<String, String> MY_MAP = ImmutableMap.of("a", "b"); }