What I am trying to achieve:
I have this piece of code I would like to improve:
As part of a Spring project (but this is really not a Spring question)
I have a straightforward piece of code that looks like this:
private String transform(String input) {
Function<String, String> transform = functionCatalog.lookup("theVeryComplexFunction");
String output = transform.apply(input);
I test coverage on the "theVeryComplexFunction" method. With that said, in my code, I would like to make available some dummies, such as:
FunctionCatalog functionCatalog = new FunctionCatalog() {
@Override
public <T> T lookup(Class<?> type, String functionDefinition, String... expectedOutputMimeTypes) {
return (T) (Function<String, String>) s -> "dummy";
}
@Override
public Set<String> getNames(Class<?> type) {
return null;
}
};
When running couple of static analysis, I am always getting:
[TypeParameterUnusedInFormals] Declaring a type parameter that is only used in the return type is a misuse of generics: operations on the type parameter are unchecked, it hides unsafe casts at invocations of the method, and it interacts badly with method overload resolution.
What I tried:
I tried removing the cast, unfortunately, it seems not to be the right direction.
Question:
How to declare this method, and be able to fix this scan result?