ClassCastException:net.sf.ezmorph.bean.MorphDynaBean cannot be cast to com.xxx.xxx

Source: Internet
Author: User


Note:

Front-End time In doing Java, you need to pass the front-end JS data and fill in the JavaBean,

JavaBean in the list to receive, as follows:

List<beanname> list;

Public list<beanname> getlist () ...

Public list<beanname> setlist (..) ...



And then at the time of the method call

1, list<beanname> userlist = User.getlist ();

2, for(Beanname bean:userlist) {

.......

}


Error message when executing to second line

ClassCastException:net.sf.ezmorph.bean.MorphDynaBean cannot be cast to Com.xxx.BeanName


At that time feeling very magical, with list<beanname> userlist can be stored user.getlist ();

Why the loop can't convert the type.

Look at the appropriate documents to find that the original Java generics only in the compile-time restricted type of role, in the runtime is not a limiting role.

You can do a mock test with the following code:

Simulate the runtime, the generic limit ignores the
		List listobj = new ArrayList ();
		Listobj.add (New Object ());
		
		Simulate compile-time, add generic limit
		list<string> liststr = new arraylist<string> ();
		Liststr.add ("test");
		
		1. You can see that any type of data at [runtime] can finally be added to the generic collection. Because there is no generic restrictions and presence in the runtime
		//2, although the code compiled this pass, there is no error prompted, but in the following loop run, it will be an error,
		Liststr.addall (listobj);
		
		Loop list test for
		(String str:liststr) {
			System.out.println (str);
		}

Exception in thread "main" Java.lang.ClassCastException:java.lang.Object cannot is cast to java.lang.String
At Com.rule.Test.main (test.java:35)


You can see that the prompt cannot be converted at the loop, which is why, "the reason that the data can be stored, but cannot traverse the loop." ”。



Summary:

And appears ClassCastException:net.sf.ezmorph.bean.MorphDynaBean cannot be cast to com.xxx.xxx

Most of the reason for this error is due to the data transmission between different languages, data encapsulation and parsing occurs, because the data transfer between different languages, the data format is not easy to control, at compile time

Errors are not reflected, only during the run will be the error.


If you are on the same language platform, such as data conversion in Java, generic discovery type is not correct, the compiler will immediately prompt error, Red Fork, compilation does not pass.










Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.