Java类操作 2021-03-27 java class, java, 类 0 评论 示例 12345public interface UserService {}public class UserServiceImpl implements UserService {} 123456789101112131415161718@SpringBootTestclass DemoApplicationTests { @Test void contextLoads() { UserServiceImpl userServiceImpl = new UserServiceImpl(); // 父类 isAssignableFrom 子类 System.out.println(UserService.class.isAssignableFrom(UserServiceImpl.class)); // true // userServiceImpl是否是UserService实例 System.out.println(userServiceImpl instanceof UserService); // true // UserService能否强转为 System.out.println(UserService.class.isInstance(userServiceImpl)); // true }} spring中常用方法 org.springframework.core.annotation.AnnotationUtils org.springframework.util.ClassUtils org.springframework.util.ReflectionUtils