Notes for Java reflection

Source: Internet
Author: User

1. for reflection class. getmethod (string name, class... parametertypes), if the element in parametertypes in the class is a numeric object type, an exception will be thrown when calling the basic type.

For example, test (long l); Class is used for calling. getmethod ("test", long. class) is unable to find the corresponding method, because the parameter is of the object type, the object type and the basic type need to be distinguished here, so the basic type can not be called during reflection

Long. Class! = Long. type; long. type = long. Class

2. Class. isassignablefrom (class <?> CLs) JDK documentation said

@ Return the booleanvalue indicating whether objects of the type CLS can be assigned to objects of this class but long. isassignablefrom (Long. class) the returned result is flase, because the jdk1.5 compiler automatically converts the basic type to the object type or converts the object type to the basic type during assign.

 

 

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.