본문으로 바로가기

ResolvableType

category Backend/Spring 2017. 12. 19. 10:30
    반응형



    참고사이트

    :https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/core/ResolvableType.html



    Encapsulates a Java Type, providing access to supertypesinterfaces, and generic parameters along with the ability to ultimately resolve to a Class.

    ResolvableTypes may be obtained from fieldsmethod parametersmethod returns or classes. Most methods on this class will themselves return ResolvableTypes, allowing easy navigation. For example:


     private HashMap<Integer, List<String>> myMap;
    
     public void example() {
         ResolvableType t = ResolvableType.forField(getClass().getDeclaredField("myMap"));
         t.getSuperType(); // AbstractMap<Integer, List<String>>
         t.asMap(); // Map<Integer, List<String>>
         t.getGeneric(0).resolve(); // Integer
         t.getGeneric(1).resolve(); // List
         t.getGeneric(1); // List<String>
         t.resolveGeneric(1, 0); // String
     }
     


    반응형