Mutual transformation between generics and entity classes

Source: Internet
Author: User

Problem:

When I cast an entity type to a generic, or cast a generic to an entity type, you are prompted not to convert.

As in the following code:

Personinfor is an entity class and T is a generic type
 Public int Getpersonmsgw_<t> (refstring  ImagePath)  {
//Generic conversion to entity type Object temp = pInfo; = (personinfor) temp;
The entity type is converted to generic = pi ; = (T) temp; return 0; }

You see, obviously, I'll assign the generic or entity type first to the middle variable, object, and then use that intermediate variable for the cast.

The reason, the generic type is a variable, can not determine which type, gu can not directly convert, and the assignment to the intermediate variable indirectly determined its type, Gartner to convert.

Above is personal opinion, the wrong place also please correct me!!

Mutual transformation between generics and entity classes

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.