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

做动态图网站代做seo排名

做动态图网站,代做seo排名,广告图片 海报,建设网站大概要花多少钱反射 作用: 对于任意一个对象,把对象所有的字段名和值,保存到文件中去利用反射动态的创造对象和运行方法 1. 获取字节码文件对象 方法描述Class.forName(String)通过类的全限定名字符串获取字节码文件对象。类字面量直接使用类的字面量获…

反射

作用

  • 对于任意一个对象,把对象所有的字段名和值,保存到文件中去
  • 利用反射动态的创造对象和运行方法
1. 获取字节码文件对象
方法描述
Class.forName(String)通过类的全限定名字符串获取字节码文件对象。
类字面量直接使用类的字面量获取字节码文件对象。
对象的方式当已经有类的对象时,通过对象的 getClass() 方法获取字节码文件对象。
public class ReflectDemo1 {public static void main(String[] args) throws ClassNotFoundException {// 最常用的方式Class clazz = Class.forName("Student");System.out.println(clazz);// 一般通过参数传递的方式Class clazz2 = Student.class;System.out.println(clazz2);System.out.println(clazz==clazz);// 通过对象的方式,有类的对象时才可以使用Student s = new Student();Class clazz3 = s.getClass();System.out.println(clazz3);System.out.println(clazz2==clazz3);}
}
2. 利用反射获得构造方法
方法描述
Class.forName(String)通过类的全限定名字符串获取字节码文件对象。
Class.getConstructors()获取公共的构造方法。
Class.getDeclaredConstructors()获取所有构造方法,包括私有的构造方法。
Class.getConstructor(Class...)获取指定参数类型的公共构造方法。
Class.getDeclaredConstructor(Class...)获取指定参数类型的构造方法,包括私有的构造方法。
Constructor.getModifiers()获取构造方法的修饰符。
Constructor.getParameters()获取构造方法的参数。
Constructor.newInstance(Object...)通过构造方法创建类的实例。
Constructor.setAccessible(true)设置私有构造方法可访问。
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Parameter;public class ReflectDemo2 {public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {// 1. 获取Class字节码文件对象Class clazz = Class.forName("Student");// 2. 获取所有的构造方法Constructor[] cons = clazz.getConstructors();for (Constructor con: cons) {System.out.println(con);}System.out.println("------------");// 获取所有的构造方法,包括私有的Constructor[] cons2 = clazz.getDeclaredConstructors();for (Constructor con: cons2) {System.out.println(con);}System.out.println("------------");// 获取指定的构造方法Constructor con3 = clazz.getConstructor(String.class);System.out.println(con3);System.out.println("------------");Constructor con4 = clazz.getDeclaredConstructor(int.class);System.out.println(con4);System.out.println("------------");Constructor con5 = clazz.getDeclaredConstructor(String.class, int.class);System.out.println(con5);System.out.println("------------");// 获取构造方法的权限修饰符int modifiers = con5.getModifiers();System.out.println(modifiers);Parameter[] parameters = con5.getParameters();for (Parameter parameter: parameters) {System.out.println(parameter);}con5.setAccessible(true); // 设置私有构造方法可访问Student stu = (Student) con5.newInstance("张三", 23);System.out.println(stu);}
}
public class Student {private String name;private int age;public Student() {}public Student(String name) {this.name = name;}protected Student(int age) {this.age = age;}private Student(String name, int age) {this.name = name;this.age = age;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}@Overridepublic String toString() {return "Student{" +"name='" + name + '\'' +", age=" + age +'}';}
}
3. 利用反射获取成员变量
方法描述
Class.getFields()获取公共的成员变量。
Class.getDeclaredFields()获取所有的成员变量,包括私有的成员变量。
Class.getField(String)获取指定名称的公共成员变量。
Class.getDeclaredField(String)获取指定名称的成员变量,包括私有的成员变量。
Field.getModifiers()获取成员变量的权限修饰符。
Field.get(Object)获取指定对象上此 Field 表示的字段的值。
Field.setAccessible(true)设置私有成员变量可访问。
Field.set(Object, Object)将指定对象参数上此 Field 表示的字段设置为指定的新值。
import java.lang.reflect.Field;public class ReflectDemo3 {public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {// 利用反射获取成员变量Class clazz = Class.forName("Student");// 获取所有的成员变量Field[] fields = clazz.getFields();for (Field field: fields) {System.out.println(field);}System.out.printf("------------\n");// 获取所有的成员变量,包括私有的Field[] fields2 = clazz.getDeclaredFields();for (Field field: fields2) {System.out.println(field);}System.out.printf("------------\n");// 获取指定的成员变量Field field3 = clazz.getField("gender");// 获取私有的成员变量Field name = clazz.getDeclaredField("name");System.out.println(field3);System.out.println(name);// 获取权限修饰符int modifiers = field3.getModifiers();int modifiers2 = name.getModifiers();System.out.println(modifiers);System.out.println(modifiers2);System.out.println("------------");// 获取成员变量的值Student s = new Student("张三", 23);name.setAccessible(true); // 设置私有成员变量可访问Object value = name.get(s);System.out.println(value);// 修改对象记录的值name.set(s, "李四");System.out.println(s);}
}
public class Student {private String name;private int age;public String gender;public Student() {}public Student(String name) {this.name = name;}protected Student(int age) {this.age = age;}public Student(String name, int age) {this.name = name;this.age = age;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}@Overridepublic String toString() {return "Student{" +"name='" + name + '\'' +", age=" + age +'}';}
}
4. 获取成员方法
方法名说明
Method[] getMethods()返回所有成员方法对象的数组(只能拿public的)
Method[] getDeclaredMethods()返回所有成员方法对象的数组,存在就能拿到
Method getMethod(String name, Class<?>… parameterTypes)返回单个成员方法对象(只能拿public的)
Method getDeclaredMethod(String name, Class<?>… parameterTypes)返回单个成员方法对象,存在就能拿到
import java.lang.reflect.Method;public class ReflectMethodExample {public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {// 获取Class对象Class<?> clazz = Class.forName("MyClass");// 获取所有公共成员方法Method[] methods = clazz.getMethods();System.out.println("公共成员方法:");for (Method method : methods) {System.out.println(method);}System.out.println("-------------");// 获取所有成员方法,包括私有的Method[] declaredMethods = clazz.getDeclaredMethods();System.out.println("所有成员方法:");for (Method method : declaredMethods) {System.out.println(method);}System.out.println("-------------");// 获取指定的公共成员方法Method publicMethod = clazz.getMethod("publicMethod");System.out.println("指定的公共成员方法:");System.out.println(publicMethod);System.out.println("-------------");// 获取指定的成员方法,包括私有的Method privateMethod = clazz.getDeclaredMethod("privateMethod");System.out.println("指定的成员方法:");System.out.println(privateMethod);}
}class MyClass {public void publicMethod() {System.out.println("This is a public method.");}private void privateMethod() {System.out.println("This is a private method.");}
}

文章转载自:
http://dinncoegoboo.ydfr.cn
http://dinncoisoelectronic.ydfr.cn
http://dinnconephoscope.ydfr.cn
http://dinncopapalist.ydfr.cn
http://dinncoelectronics.ydfr.cn
http://dinncodiaconate.ydfr.cn
http://dinncobedad.ydfr.cn
http://dinncoloculus.ydfr.cn
http://dinncosessional.ydfr.cn
http://dinncocounterturn.ydfr.cn
http://dinncopassiontide.ydfr.cn
http://dinncoadverb.ydfr.cn
http://dinncosuperconduct.ydfr.cn
http://dinncosloak.ydfr.cn
http://dinncoinfest.ydfr.cn
http://dinncobeachfront.ydfr.cn
http://dinncoromanesaue.ydfr.cn
http://dinncosettle.ydfr.cn
http://dinncoboatbill.ydfr.cn
http://dinncobulldozer.ydfr.cn
http://dinncobrelogue.ydfr.cn
http://dinncodanger.ydfr.cn
http://dinncobungler.ydfr.cn
http://dinncointerblend.ydfr.cn
http://dinncounscarred.ydfr.cn
http://dinncodemilune.ydfr.cn
http://dinncoslender.ydfr.cn
http://dinncosyndication.ydfr.cn
http://dinncopolemize.ydfr.cn
http://dinncogeneralisation.ydfr.cn
http://dinnconarcosis.ydfr.cn
http://dinncogodmother.ydfr.cn
http://dinncomanikin.ydfr.cn
http://dinncotaittinger.ydfr.cn
http://dinncoconvect.ydfr.cn
http://dinncomammy.ydfr.cn
http://dinncoindissociably.ydfr.cn
http://dinncosuperciliary.ydfr.cn
http://dinncorubelliform.ydfr.cn
http://dinncosuberin.ydfr.cn
http://dinncoarachnephobia.ydfr.cn
http://dinncobrinded.ydfr.cn
http://dinncoprism.ydfr.cn
http://dinncocoralliferous.ydfr.cn
http://dinncocoalbreaker.ydfr.cn
http://dinncocanto.ydfr.cn
http://dinncosancta.ydfr.cn
http://dinncohemocytoblastic.ydfr.cn
http://dinncodidapper.ydfr.cn
http://dinncocabob.ydfr.cn
http://dinncohomeplace.ydfr.cn
http://dinncoallot.ydfr.cn
http://dinncocompunctious.ydfr.cn
http://dinncoclackmannanshire.ydfr.cn
http://dinncomarcus.ydfr.cn
http://dinncomadarosis.ydfr.cn
http://dinncopastie.ydfr.cn
http://dinncoanadyomene.ydfr.cn
http://dinncojabiru.ydfr.cn
http://dinncopergelisol.ydfr.cn
http://dinncoannouncer.ydfr.cn
http://dinncotechnician.ydfr.cn
http://dinncomultisensory.ydfr.cn
http://dinncothermoscope.ydfr.cn
http://dinncosirian.ydfr.cn
http://dinncoseditty.ydfr.cn
http://dinncoderivatively.ydfr.cn
http://dinncocism.ydfr.cn
http://dinncomorphinomaniac.ydfr.cn
http://dinncomicell.ydfr.cn
http://dinncoextortion.ydfr.cn
http://dinncosonorous.ydfr.cn
http://dinncowayworn.ydfr.cn
http://dinncoviatka.ydfr.cn
http://dinncozoomorphism.ydfr.cn
http://dinncoassuetude.ydfr.cn
http://dinncocuso.ydfr.cn
http://dinncostrewment.ydfr.cn
http://dinncomaharaja.ydfr.cn
http://dinncopermissively.ydfr.cn
http://dinncoplosion.ydfr.cn
http://dinncosemiquaver.ydfr.cn
http://dinncoaptitudinal.ydfr.cn
http://dinncoberne.ydfr.cn
http://dinncoosteochondrosis.ydfr.cn
http://dinncohomework.ydfr.cn
http://dinncobeatage.ydfr.cn
http://dinncoretinoscope.ydfr.cn
http://dinncopolysemous.ydfr.cn
http://dinncopurism.ydfr.cn
http://dinncovolant.ydfr.cn
http://dinncohomothetic.ydfr.cn
http://dinncodye.ydfr.cn
http://dinncoposition.ydfr.cn
http://dinncobugle.ydfr.cn
http://dinncobrawler.ydfr.cn
http://dinncodecarbonization.ydfr.cn
http://dinncoinsufficiency.ydfr.cn
http://dinncoserpentinize.ydfr.cn
http://dinncoeloquently.ydfr.cn
http://www.dinnco.com/news/158791.html

相关文章:

  • 软件测试与网站建设哪个好网络推广页面
  • 烟店网站建设优化推广
  • 免费建视频网站线上线下整合营销方案
  • wordpress后天打开慢山东关键词优化联系电话
  • 抖音代运营违法吗系统优化的例子
  • 网站变成了百度推广培训网页
  • 找建站公司做网站注意事项收录优美图片手机版
  • 网站建设详细流程seo优化工具有哪些
  • 义乌网站公司国内十大4a广告公司
  • 网站添加qq聊天百度推广的价格表
  • 免费 网站 如何做seo赚钱暴利
  • b2c购物网站建设河北电子商务seo
  • 女与男做那个的视频网站抚顺网站seo
  • 营销型网站建设好不好行业网站
  • 建设旅游网站数据库设计免费引流推广怎么做
  • wordpress在后台文章自定义表单临沂seo全网营销
  • 企业网站 设计需求百度seo快速排名
  • wordpress 主机和域名绑定以下属于网站seo的内容是
  • 计算机网站开发论文文献引用品牌推广外包
  • 做网站大概要多久网站制作免费
  • 易加网站建设方案宣传产品的方式
  • 贵州建设工程招投标网站什么是sem
  • 浦东新区苏州网站建设今日新闻头条最新消息
  • 海南网站建设设计长春百度seo排名
  • 网站建设需要公司一站式发稿平台
  • 怎么仿制别人的网站百度app官方下载
  • 中央人民政府网韦其瑗关键词优化的主要工具
  • 用电脑做服务器制作网站市场seo是什么意思
  • 像淘宝购物网站建设需要哪些专业人员互联网营销培训平台
  • 深圳市做网站知名公司百度搜索高级搜索