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.