Spring getBean with type validation
问题 I'm using the method ApplicationContext.getBean(String name, Class requiredType). The bean is of type util:set. My code looks like: Set<String> mySet = context.getBean("myBean", Set.class); I want to know is how to do something like this to avoid the type casting warning: Set<String> mySet = context.getBean("myBean", Set<String>.class); I'm not sure if it's possible to define the type of a class in this way. Am I dreaming or is there a way to do this? Thanks. 回答1: Not really but there is a