preprocess
accepts parameter(s) of a concrete collection type150
151 private static final class LongPreprocessor implements IParameterPreprocessor {
152 @SuppressWarnings("PMD.ReplaceVectorWithList")
153 @Override public boolean preprocess(Stack<String> args,154 CommandSpec commandSpec, ArgSpec argSpec, Map<String, Object> info) {155 args.replaceAll(arg -> arg.replace("_", ""));156 return false;157 }158 }
159}
getCacheManager
accepts parameter(s) of a concrete collection type 92 }
93
94 @Override
95 public CacheManager getCacheManager(URI uri, ClassLoader classLoader, Properties properties) { 96 URI managerURI = getManagerUri(uri); 97 ClassLoader managerClassLoader = getManagerClassLoader(classLoader); 98 99 synchronized (cacheManagers) {100 Map<URI, CacheManager> cacheManagersByURI = cacheManagers.computeIfAbsent(101 managerClassLoader, any -> new HashMap<>());102 return cacheManagersByURI.computeIfAbsent(managerURI, any -> {103 Properties managerProperties = (properties == null) ? getDefaultProperties() : properties;104 return new CacheManagerImpl(this, isOsgiComponent,105 managerURI, managerClassLoader, managerProperties);106 });107 }108 }109
110 @Override
111 public void close() {
Concrete collection types (such as ArrayList
, HashMap
, etc.) should not be used in a public
method's signature.
Java encourages the use of abstract types/interfaces at the API boundary over concrete types. This helps one design generic APIs that are easy to modify and extend.
Although designing generic APIs is generally preferable, one should especially emphasize their use over concrete types when elements of the collection API are involved. This is because almost all non-trivial Java applications depend heavily on abstract types defined in Java's collection framework.
// Return type is `ArrayList` instead of `List`.
public ArrayList<Integer> method() {
// ..rest of the code
}
// Parameter type is `HashMap` instead of `Map`.
public void methodWithParams(HashMap<String, String> demo) {
// ..rest of the code
}
Consider using abstract types in return values and parameters of public
methods.
public List<Integer> method() {
// ..rest of the code
}
public void methodWithParams(Map<String, String> demo) {
// ..rest of the code
}