当前位置: 首页 > news >正文

营销型企业网站建设 广义的空间/网站站点

营销型企业网站建设 广义的空间,网站站点,门户网站建设摘要,社区微网站建设方案ppt模板下载Java反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法;对于任意一个对象,都能够调用它的任意一个方法;这种动态获取的信息以及动态调用对象的方法的功能称为Java语言的反射机制。 下面是jdk7…

Java反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法;对于任意一个对象,都能够调用它的任意一个方法;这种动态获取的信息以及动态调用对象的方法的功能称为Java语言的反射机制。
下面是jdk7的文档内容:

public Field getDeclaredField(String name)throws NoSuchFieldException,SecurityException

Returns a Field object that reflects the specified declared field of the class or interface represented by this Class object. The name parameter is a String that specifies the simple name of the desired field. Note that this method will not reflect the length field of an array class.
Parameters:
name - the name of the field
Returns:
the Field object for the specified field in this class
Throws:
NoSuchFieldException - if a field with the specified name is not found.
NullPointerException - if name is null
SecurityException - If a security manager, s, is present and any of the following conditions is met:
invocation of s.checkMemberAccess(this, Member.DECLARED) denies access to the declared field
the caller’s class loader is not the same as or an ancestor of the class loader for the current class and invocation of s.checkPackageAccess() denies access to the package of this class
public final class Field
extends AccessibleObject
implements Member
A Field provides information about, and dynamic access to, a single field of a class or an interface. The reflected field may be a class (static) field or an instance field.
A Field permits widening conversions to occur during a get or set access operation, but throws an IllegalArgumentException if a narrowing conversion would occur.

public void set(Object obj,Object value)throws IllegalArgumentException,IllegalAccessException

Sets the field represented by this Field object on the specified object argument to the specified new value. The new value is automatically unwrapped if the underlying field has a primitive type.

public Object get(Object obj)throws IllegalArgumentException,IllegalAccessException

Returns the value of the field represented by this Field, on the specified object. The value is automatically wrapped in an object if it has a primitive type.
setAccessible是Field的父类AccesibleObject中方法

public void setAccessible(boolean flag)throws SecurityException

Set the accessible flag for this object to the indicated boolean value. A value of true indicates that the reflected object should suppress(禁止) Java language access checking when it is used. A value of false indicates that the reflected object should enforce Java language access checks.
First, if there is a security manager, its checkPermission method is called with a ReflectPermission(“suppressAccessChecks”) permission.

A SecurityException is raised if flag is true but accessibility of this object may not be changed (for example, if this element object is a Constructor object for the class Class).

A SecurityException is raised if this object is a Constructor object for the class java.lang.Class, and flag is true.
一段简单的代码:(设置私有属性的getter和setter方法)

import java.lang.reflect.Field;
public class ReflectHello{public static void main(String[] args){String objstr = "BurningT.Hello";try {Class<?> cl = Class.forName(objstr);Object helloBean = cl.newInstance();Field[] helloA =    cl.getDeclaredFields();for (Field f1:helloA){f1.setAccessible(true);System.out.println(f1.get(helloBean));f1.set(helloBean, "123");System.out.println(f1.get(helloBean));  f1.setAccessible(false);f1.set(helloBean,"123");}} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}catch (InstantiationException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IllegalAccessException e) {// TODO Auto-generated catch blocke.printStackTrace();}catch (SecurityException e) {// TODO Auto-generated catch blocke.printStackTrace();}}
}

运行结果:
null
123
java.lang.IllegalAccessException: Class ReflectHello can not access a member of class BurningT.Hello with modifiers “private”
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
at java.lang.reflect.Field.doSecurityCheck(Field.java:959)
at java.lang.reflect.Field.getFieldAccessor(Field.java:896)
at java.lang.reflect.Field.set(Field.java:657)
at ReflectHello.main(ReflectHello.java:18)
method.invoke方法的返回值:
the result of dispatching the method represented by this object on obj with parameters args

来自google翻译
使用参数args在obj上调度此对象表示的方法的结果

http://www.jmfq.cn/news/4794031.html

相关文章:

  • wordpress网站配置文件/企业短视频推广
  • 专业写作网站/怎么建立公司网站
  • 做视频网站的挣钱吗/域名交易平台
  • 做网站建设需要做哪些工作/软文营销案例
  • 如何仿做网站/百度快照查询入口
  • 如何制作自己的网站 可放广告/广告推广免费平台
  • 最好的wordpress/北京网站优化指导
  • 怎么做基金公司网站/关键词排名工具有哪些
  • 从网络营销角度做网站/seoyoon
  • 建设部网站如何下载国标规范/创建网站需要多少资金
  • 蔡文胜做的个人网站/云南百度公司
  • 专业网站定制哪家好/郑州厉害的seo顾问公司
  • 网站建设论文选题/哪个网站学seo是免费的
  • 在拼多多开网店的流程/网站优化入门免费教程
  • 网站开发文章/快手作品免费推广软件
  • 怎么做收费网站/今日头条新闻发布
  • 新浪门户网站是谁做的/今日全国疫情一览表
  • wordpress submenu/济南优化哪家好
  • 微商城页面设计/电脑系统优化工具
  • 网站建设图片居中代码/seo优化是做什么的
  • 高明网站设计服务/怎么把产品快速宣传并推广
  • 网站建设栏目/苏州百度推广公司地址
  • qq游戏做任务领铜板网站/成都网络营销公司排名
  • 软件开发属于什么专业/企业网站优化方案
  • 保定网站设计公司/推广赚佣金
  • 免费二级域名空间注册/seo深圳培训班
  • 陕西建设机械股份有限公司网站/博客是哪个软件
  • 网站做404好处/seo排名优化推广报价
  • 免费个人业务网站制作/网站seo优化外包顾问
  • 手机端企业网站怎么做/百度怎么做关键词优化