InvalidCastException: Cannot cast from source type to destination type.
Cannot convert from source type to target type.
The main reason for this problem is that there are errors in type conversion, one of which is not easy to detect is that there are errors when the parent class is cast to a subclass, that is, there may be errors when the transition is down in polymorphism
What is polymorphism: the pointer of the parent class points to the subclass and calls the method of the subclass
First let’s see where my code problem is, for your reference
Obviously, when I was in new tmphead, the pointer of the parent class did not point to the child class at all, so there would be no downward transformation.
We just need to change my code in this way to create a new subclass object..
Read More:
- [Solved] Failed to convert value of type ‘java.lang.String‘ to required type ‘java.util.Date‘;
- [Solved] SpringBoot Project Startup Error: Field userMapper in com.demo.controller.MemberController required a bean of type ‘c
- [Solved] Java.util.linkedhashmap cannot be cast to entity class
- OpenFeignClient Use Object to Receive text/plain Type Return Error
- [Solved] BindingException: Type interface XXX is not known to the MapperRegistry
- Explicit and implicit conversion of Java data type
- Java Error: No enclosing instance of type Main is accessible. Must qualify the allocation with an encl
- feign.codec.EncodeException: Type definition error: [simple type, class java.util.Collections$3]
- [Solved] IDEA JPA Custome Query Error: Can‘t resolve symbol ‘Type‘
- [Solved] POI error: Package should contain a content type part [M1.13]
- [Solved] swagger Docmentation Access Error: Illegal DefaultValue 1024 for parameter type integer, java.lang.NumberFormatException
- Defining a bean of type ‘org.springframework.data.redis.core.RedisTemplate‘ in your configuration.
- [Solved] Consider defining a bean of type ‘org.springframework.data.redis.core.RedisTemplate‘ in your configu
- [Solved] ElasticsearchStatusException[Elasticsearch exception [type=mapper_parsing_exception, reason=failed t
- springboot jsp: There was an unexpected error (type=Not Found, status=404). No message available
- [Solved] Java.lang.IllegalStateException: Type handler was null on parameter mapping for property ‘__frch_it
- Springboot startup error: Field elasticsearchRestTemplate in cn.lili.modules.material.serviceImpl.QrMaterialServiceImpl required a bean of type
- Java back end receives localdatetime type parameter
- [Solved] Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type…
- [Solved] No validator could be found for constraint ‘javax.validation.constraints.NotBlank’ validating type ‘java.lang.String’