Skip to content

io microsphere util TypeFinder

github-actions[bot] edited this page Mar 21, 2026 · 14 revisions

TypeFinder

Type: Class | Module: microsphere-java-core | Package: io.microsphere.util | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/util/TypeFinder.java

Overview

A utility class for finding related types based on a given type.

This class allows searching for various related types such as:

- Self (the type itself)
- Direct superclass
- Interfaces directly implemented by the type
- Hierarchical types (recursive search through superclasses and interfaces)

Example Usage

`// Find all hierarchical types of String.class including itself
TypeFinder> finder = TypeFinder.classFinder(String.class, TypeFinder.Include.HIERARCHICAL);
List> types = finder.getTypes();

// Find only interfaces implemented by ArrayList.class
TypeFinder> finder = TypeFinder.classFinder(ArrayList.class, TypeFinder.Include.INTERFACES);
List> interfaceTypes = finder.getTypes();

// Custom combination: include self and interfaces but not superclass
TypeFinder> finder = new TypeFinder<>(MyClass.class,
    TypeFinder.classGetSuperClassFunction,
    TypeFinder.classGetInterfacesFunction,
    true,  // includeSelf
    false, // includeHierarchicalTypes
    false, // includeSuperclass
    true); // includeInterfaces
`

Declaration

public class TypeFinder<T>

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

// Find all hierarchical types of String.class including itself
TypeFinder<Class<?>> finder = TypeFinder.classFinder(String.class, TypeFinder.Include.HIERARCHICAL);
List<Class<?>> types = finder.getTypes();

// Find only interfaces implemented by ArrayList.class
TypeFinder<Class<?>> finder = TypeFinder.classFinder(ArrayList.class, TypeFinder.Include.INTERFACES);
List<Class<?>> interfaceTypes = finder.getTypes();

// Custom combination: include self and interfaces but not superclass
TypeFinder<Class<?>> finder = new TypeFinder<>(MyClass.class,
    TypeFinder.classGetSuperClassFunction,
    TypeFinder.classGetInterfacesFunction,
    true,  // includeSelf
    false, // includeHierarchicalTypes
    false, // includeSuperclass
    true); // includeInterfaces

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.util.TypeFinder;

API Reference

Public Methods

Method Description
getTypes
findTypes
classFinder
classFinder
genericTypeFinder
genericTypeFinder

See Also

  • Type

This documentation was auto-generated from the source code of microsphere-java.

Home

annotation-processor

java-annotations

java-core

java-test

jdk-tools

lang-model

Clone this wiki locally