accessibleobject_inaccessible_iaccessible接口

1个回答

写回答

zhhsdjjsj

01月16日

+ 关注

Conveniencemethodtosettheaccessibleflagforanarrayofobjectswithasinglesecuritycheck(forefficiency)。First,ifthereisasecuritymanager,itscheckPermissionmethodiscalledwithaReflectPermission("suppressAccessChecks")permission。

ASecurityExceptionisraisedifflagistruebutaccessibilityofanyoftheelementsoftheinputarraymaynotbechanged(forexample,iftheelementobjectisaConstructorobjectfortheclassClass)。

IntheeventofsuchaSecurityException,theaccessibilityofobjectsissettoflagforarrayelementsupto(andexcluding)theelementforwhichtheexceptionoccurred;theaccessibilityofelementsbeyond(andincluding)theelementforwhichtheexceptionoccurredisunchanged。

publicvoidsetAccessible(booleanflag)throwsSecurityExceptionSettheaccessibleflagforthisobjecttotheindicatedbooleanvalue。

AvalueoftrueindicatesthatthereflectedobjectshouldsuppressJavalanguageaccesscheckingwhenitisused。AvalueoffalseindicatesthatthereflectedobjectshouldenforceJavalanguageaccesschecks。

First,ifthereisasecuritymanager,itscheckPermissionmethodiscalledwithaReflectPermission("suppressAccessChecks")permission。

ASecurityExceptionisraisedifflagistruebutaccessibilityofthisobjectmaynotbechanged(forexample,ifthiselementobjectisaConstructorobjectfortheclassClass)。

ASecurityExceptionisraisedifthisobjectisaConstructorobjectfortheclassjava。lang。Class,andflagistrue。publicbooleanisAccessible()public<TextendsAnnotation>TgetAnnotation(Class<T>annotationClass)publicbooleanisAnnotationPresent(Class<extendsAnnotation>annotationClass)publicAnnotation[]getAnnotations()publicAnnotation[]getDeclaredAnnotations()Returnsallannotationsthataredirectlypresentonthiselement。

Unliketheothermethodsinthisintece,thismethodignoresinheritedannotations。(Returnsanarrayoflengthzeroifnoannotationsaredirectlypresentonthiselement。

)Thecallerofthismethodisfreetomodifythereturnedarray;itwillhavenoeffectonthearraysreturnedtoothercallers。

举报有用(6分享收藏

Copyright © 2025 IZhiDa.com All Rights Reserved.

知答 版权所有 粤ICP备2023042255号