今天学习多态,向下强制类型转换过程中,遇到一个报错信息:class Polymorphic2. Person cannot be cast to class Polymorphic2. Man
上网查询后说是maven里面的pom.xml配置文件出错,采用了热部署,需要注释如下代码段
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
查询后找到pom.xml文件位于E:\eclipse-java-2021-12-R-win32-x86_64\configuration\org.eclipse.osgi\253\0\.cp\META-INF\maven\org.eclipse.m2e\org.eclipse.m2e.core.ui
打开后发现并没有这段代码,于是检查自己代码是否正确。
这段代码能够通过编译,但是运行时报错class Polymorphic2. Person cannot be cast to class Polymorphic