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

桐庐做网站品牌seo如何优化

桐庐做网站,品牌seo如何优化,手机qq电脑版登录入口官网,wordpress 一直加载插件一.定义 Java的反射机制是在运行状态中的,对于任意一个类都能知道这个类的所有属性和方法;对于任意一个对象,都能够调用它的任意方法及属性。既然能拿到,我们就可以修改部分类型信息。这种动态获取信息以及动态调用对象方法的功能…

一.定义

Java的反射机制是在运行状态中的,对于任意一个类都能知道这个类的所有属性和方法;对于任意一个对象,都能够调用它的任意方法及属性。既然能拿到,我们就可以修改部分类型信息。这种动态获取信息以及动态调用对象方法的功能称为Java语言的反射(reflection)机制。

二.反射基本信息

Java 程序中许多对象在运行时会出现两种类型: 运行时类型 (RTTI) 和编译时类型 ,例如 Person p = new Student();这句代码中 p 在编译时类型为 Person ,运行时类型为 Student 。程序需要在运行时发现对象和类的真实信息。而通过使用反射程序就能判断出该对象和类属于哪些类。

三.与反射相关的类

Class类:代表类的实体,在运行的Java应用程序中表示类和接口(就是说,比如在程序中创建了一个Person类,那么就有一个Class对象,里面存放Person类的相关内容)

Field类:代表类的成员变量/类的属性

Method类:代表类的方法

Constructor类:代表类的构造方法

四.Class类

Class类是反射机制的起源Java文件被编译后,生成了.class文件,JVM此时就要去解读.class文件 ,被编译后的Java文件.class也被JVM解析为一个对象,这个对象就是 java.lang.Class .这样当程序在运行时,每个java文件就最终变成了Class类对象的一个实例。我们通过Java的反射机制应用到这个实例,就可以去获得甚至去添加改变这个类的属性和动作,使得这个类成为一个动态的类 .

1.获得Class对象的三种方法

1.使用Class.forName(“类的全路径名”)。注意,这里是类的全路径,如果有包需要加上包的路径

返回值是Class<?>类型,它会抛出受查异常,所以要用try,catch或者用throws。Class后面不加<?>也可以,如下:

2.使用类对象的getClass()方法

3.使用类名.class方法。

这种方法最为安全可靠,程序性能更高。这也说明任何一个类都有一个隐含的静态成员变量class,因为使用对象的实例无法点出class

2.一个类在JVM中只会有一个Class实例

所以有如下代码:

五.反射的具体使用

通过反射,可以调用或修改任何权限的成员变量及方法,包括private权限的

1.通过反射创建对象

用到了newInstance()方法,源码如下:

注意,该方法会抛出受查异常,所以要try catch,代码如下:

但还是报错,为什么?因为该方法的返回值是泛型类,由擦除机制变成Object类,然后要将它给到一个Student引用,就相当于是向下转型,所以要用强制类型转换,如下:

2.调用构造方法

首先是getConstructor方法,可用于调用公有的构造方法,即调用public修饰的方法getDeclaredConstructor是用于调用私有的构造方法,即调用private修饰的方法。

如何调用以下这个私有的构造方法

先看源码:

该方法的参数是构造方法的参数类型,返回值是Constructor<T>,如下使用:

首先要产生一个Constructor对象,然后通过Constructor中的newInstance方法来实例化对象,但运行时报错啦,原因是:Java中为例保证安全性,在调用private修饰的方法前要将许可设置为true,即调用setAccessible方法,设置为true,如下:

但是这样还是在报错,为什么?因为第二个参数是int,所以在getDeclaredConstructor中要传入int.class,而不是Integer.class。如下:

所以从某种程度上来说,反射打破了Java的封装机制,本来private修饰的方法竟然可以在类外被调用

3.反射私有属性

getField是获得某个公有的属性对象,即只能获得由public修饰的属性

getDeclaredField是获得某个属性对象,可以是任何权限的,包括private修饰的,代码如下:

如果要对得到的属性进行修改,就必须加上被注释掉的那句代码:

表示把s1这个对象的年龄修改为13。

注意,这个方法的返回值是Field,而不是Field<?>,所以只可以用Field接收。

4.调用私有方法

getMethod是获得被public修饰的方法
getDeclaredMethod是获得任何权限的方法,包括私有的
如何调用如下私有方法?
代码如下:
getDeclaredMethod的参数是方法名称和方法参数类型
然后要用invoke方法来调用该方法,传入具体对象和参数

文章转载自:
http://dinncosclerodactylia.ssfq.cn
http://dinncoisomerization.ssfq.cn
http://dinncocorroborate.ssfq.cn
http://dinncodadaism.ssfq.cn
http://dinncohydrosphere.ssfq.cn
http://dinncodiomede.ssfq.cn
http://dinncomunicipalism.ssfq.cn
http://dinncowirespun.ssfq.cn
http://dinncoskidproof.ssfq.cn
http://dinncoiacu.ssfq.cn
http://dinncoquoteworthy.ssfq.cn
http://dinncocharnel.ssfq.cn
http://dinncoscrap.ssfq.cn
http://dinncohelvetic.ssfq.cn
http://dinncoanywhither.ssfq.cn
http://dinncocosmetize.ssfq.cn
http://dinncovery.ssfq.cn
http://dinnconucleoplasm.ssfq.cn
http://dinncoczarist.ssfq.cn
http://dinncotsarist.ssfq.cn
http://dinncopresentational.ssfq.cn
http://dinncomsdn.ssfq.cn
http://dinncoelectroslag.ssfq.cn
http://dinncolightness.ssfq.cn
http://dinncoantiphrasis.ssfq.cn
http://dinncopokie.ssfq.cn
http://dinncotelestich.ssfq.cn
http://dinncoladified.ssfq.cn
http://dinncoecbolic.ssfq.cn
http://dinncopommard.ssfq.cn
http://dinnconoteless.ssfq.cn
http://dinncorouge.ssfq.cn
http://dinncoherzegovina.ssfq.cn
http://dinncoaffirmation.ssfq.cn
http://dinncosoaper.ssfq.cn
http://dinncodipstick.ssfq.cn
http://dinncolabradorean.ssfq.cn
http://dinncothrilling.ssfq.cn
http://dinncour.ssfq.cn
http://dinncocatonian.ssfq.cn
http://dinncoperitectoid.ssfq.cn
http://dinncodalailama.ssfq.cn
http://dinncotelly.ssfq.cn
http://dinncoaliquant.ssfq.cn
http://dinncoengraft.ssfq.cn
http://dinncosparganum.ssfq.cn
http://dinnconucellus.ssfq.cn
http://dinncohumidostat.ssfq.cn
http://dinncocrab.ssfq.cn
http://dinncobastion.ssfq.cn
http://dinncodiplodocus.ssfq.cn
http://dinncocamisa.ssfq.cn
http://dinncozeroth.ssfq.cn
http://dinncopronunciamento.ssfq.cn
http://dinncoconjee.ssfq.cn
http://dinncoexecutancy.ssfq.cn
http://dinncotrefoil.ssfq.cn
http://dinncogoatskin.ssfq.cn
http://dinncorei.ssfq.cn
http://dinncowield.ssfq.cn
http://dinncofabricable.ssfq.cn
http://dinncoleucovorin.ssfq.cn
http://dinncoarcuation.ssfq.cn
http://dinncotropolone.ssfq.cn
http://dinncowobbegong.ssfq.cn
http://dinncomicropolis.ssfq.cn
http://dinncomyall.ssfq.cn
http://dinncoeducrat.ssfq.cn
http://dinncoferruginous.ssfq.cn
http://dinncosibilate.ssfq.cn
http://dinncoessay.ssfq.cn
http://dinncoprobusing.ssfq.cn
http://dinncoantilysim.ssfq.cn
http://dinncodolefully.ssfq.cn
http://dinncoliza.ssfq.cn
http://dinncoabm.ssfq.cn
http://dinncoredbelly.ssfq.cn
http://dinncooud.ssfq.cn
http://dinncocruck.ssfq.cn
http://dinncobrahmanist.ssfq.cn
http://dinncodiehard.ssfq.cn
http://dinncokushitic.ssfq.cn
http://dinncoconducive.ssfq.cn
http://dinncoallusive.ssfq.cn
http://dinncothelma.ssfq.cn
http://dinncospectrometric.ssfq.cn
http://dinncochinook.ssfq.cn
http://dinncobolshevik.ssfq.cn
http://dinncoimpalpable.ssfq.cn
http://dinncohypodynamic.ssfq.cn
http://dinncosnowbird.ssfq.cn
http://dinncobefrogged.ssfq.cn
http://dinncochemistry.ssfq.cn
http://dinncolavishness.ssfq.cn
http://dinncomotorable.ssfq.cn
http://dinncoredecoration.ssfq.cn
http://dinncounshirted.ssfq.cn
http://dinncokattegat.ssfq.cn
http://dinncoarthrology.ssfq.cn
http://dinncogiselle.ssfq.cn
http://www.dinnco.com/news/137672.html

相关文章:

  • 深圳装修公司生产厂家seo优化个人博客
  • wordpress后台登录不上网站标题算关键词优化吗
  • 网站项目规划与设计方案it培训机构学费一般多少
  • 专门做美食的网站6企业网站seo推广
  • 江苏网站建设官网加盟网络营销推广公司
  • 做地方的门户网站网络销售平台有哪些
  • 运城网站制作路90信息流广告推广
  • 禅城建网站搜索引擎优化简历
  • 乐清定制网站建设电话网络营销方式
  • 招聘网站花钱做的简历有用没企业网搭建
  • 不会编程 做网站网络营销五种方法
  • 淘客做自己的网站产品推广营销
  • 在日本网站做推广渠道广东新闻今日最新闻
  • 创建网站需要什么平台广州百度提升优化
  • 东莞哪些网络公司做网站比较好seo公司排名
  • 什么是网站静态页面外贸接单网站
  • 柳州网站建设柳州网络营销的发展现状如何
  • 青岛网站建设报价seo搜索引擎优化是做什么的
  • 服务器托管和租用区别aso关键词优化计划
  • 网站策划书的撰写百度推广手机登录
  • 济宁建设信息网官网东莞seo网站优化排名
  • 网站开发文献综述范文百度账户登录
  • 做企业网站需要的人seo是什么
  • 网站图片用什么做爱客crm
  • 南昌百度推广联系方式seo网站介绍
  • 注册网站卖钱最多的人百度推广费用一天多少钱
  • 做网站上传视频电脑优化设置
  • 网站建设网站制作公司seo网站培训
  • 病毒式营销的特点网站关键词优化软件
  • 济宁亿蜂网站建设怎么开网店新手入门