Search recursively through the type hierarchy of cl (superclasses and interfaces) to find the Candidate class.
Search recursively through the type hierarchy of cl (superclasses and interfaces) to find the Candidate class. If found return the first type parameter's type value.
In other words: Given a method with a generic result type, this function can be used to find out how a superclass or implemented interface is parameterized.
For example, a method getList() returns a List[String]. We are not interested which type parameter List is applied to but which type parameter Iterable, which is a supertype of List, is applied to.
tp is the list of type values applied to type cl. While traversing the type hierarchy, the type parameters have to be resolved in the context of the current class.
Example: Candidate = Iterable cl tp ArrayList[String] [] => getGenericInterface ParameterizedType(List,Class String) [] => resolved:String List [String]=> getGenericInterface ParameterizedType(Collection,E) [String]=> resolved: TypeVariable(E,List) => String Collection [String]=> getGenericInterface ParameterizedType(Iterable,E) [String]=> resolved: TypeVariable(E,Collection) => String Iterable [String]=> String