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

销售网站开发意义做食物的网站

销售网站开发意义,做食物的网站,临海建设规划信息网网站,composer 发布wordpress入门级笔记-反射 一、利用反射破泛型集合二、Student类三、获取构造器的演示和使用1.getConstructors只能获取当前运行时类的被public修饰的构造器2.getDeclaredConstructors:获取运行时类的全部修饰符的构造器3.获取指定的构造器3.1得到空构造器3.2得到两个参数的有参构造器3.3得到一个参数的有参构造器并且是private修饰的 4.有了构造器以后我就可以创建对象 四、获取属性的演示和使用1.getFields获取运行时类和父类中被public修饰的属性2.getDeclaredFields获取运行时类中的所有属性3.获取指定的属性4.属性的具体结构4.1获取修饰符4.2获取属性的数据类型4.3获取属性的名字4.4给属性赋值(给属性设置值必须要有对象) 五、获取方法的演示与应用1.getMethods:获取运行时类的方法还有所有父类中的方法被public修饰2.getDeclaredMethods:获取运行时类中的所有方法常用3.获取指定的方法4.调用方法 六、获取运行时类的接口总结 一、利用反射破泛型集合 public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {//用反射来破泛型集合/*** 泛型集合限制存入集合中的变量类型* 但是这种限制只出现在编码/编译期。* 运行期是没有泛型反射恰好就是在运行期执行*/ArrayListString list new ArrayList();list.add(123);Class cls ArrayList.class;Method add cls.getMethod(add, Object.class);add.invoke(list,34);add.invoke(list,false);System.out.println(list);//运行期无泛型}运行结果 二、Student类 public class Student extends Person implements MyInterface {private int sno;//学号double height;//身高protected double weight;//体重public double score;//成绩public String banji;public String showInfo(){return 我是一名三好学生;}public String showInfo(int a,int b){return 重载方法我是一名三好学生;}private void work(){System.out.println(我以后会找工作--成为码农 程序员 程序猿 程序媛);}void happy(){System.out.println(做人最重要的就是开心每一天);}protected int getSno(){return sno;}Overridepublic void myMethod() {System.out.println(我重写了myMethod方法。。);}public Student() {}public Student(int sno) {this.sno sno;}public Student(int sno, double weight) {this.sno sno;this.weight weight;}private Student(double height) {this.height height;}public Student(int sno, double height, double weight, double score) {this.sno sno;this.height height;this.weight weight;this.score score;}Overridepublic String toString() {return Student{ sno sno , height height , weight weight , score score };} }三、获取构造器的演示和使用 //获取字节码信息Class cls Student.class;//通过字节码信息可以获取构造器1.getConstructors只能获取当前运行时类的被public修饰的构造器 代码如下示例 Constructor[] c1 cls.getConstructors();for(Constructor c:c1){System.out.println(c);}运行结果 2.getDeclaredConstructors:获取运行时类的全部修饰符的构造器 代码如下示例 Constructor[] c2 cls.getDeclaredConstructors();for(Constructor c:c2){System.out.println(c);}运行结果 3.获取指定的构造器 3.1得到空构造器 Constructor con1 cls.getConstructor();System.out.println(con1);运行结果 3.2得到两个参数的有参构造器 Constructor con2 cls.getConstructor(int.class, double.class);System.out.println(con2);运行结果 3.3得到一个参数的有参构造器并且是private修饰的 Constructor con3 cls.getDeclaredConstructor(int.class);System.out.println(con3);运行结果 4.有了构造器以后我就可以创建对象 Object o1 con1.newInstance();System.out.println(o1);Object o2 con2.newInstance(180120111, 170.6);System.out.println(o2);运行结果 四、获取属性的演示和使用 //获取字节码信息Class cls Student.class;1.getFields获取运行时类和父类中被public修饰的属性 Field[] fields cls.getFields();for(Field f:fields){System.out.println(f);}运行结果 2.getDeclaredFields获取运行时类中的所有属性 Field[] declaredFields cls.getDeclaredFields();for(Field f:declaredFields){System.out.println(f);}运行结果 3.获取指定的属性 Field score cls.getField(score);System.out.println(score);Field sno cls.getDeclaredField(sno);System.out.println(sno);运行结果 4.属性的具体结构 4.1获取修饰符 //获取指定的属性Field score cls.getField(score);System.out.println(score);Field sno cls.getDeclaredField(sno);System.out.println(sno);System.out.println(---------------------); // //属性的具体结构 // //获取修饰符/*int modifiers sno.getModifiers();System.out.println(modifiers);System.out.println(Modifier.toString(modifiers));*/System.out.println(Modifier.toString(sno.getModifiers()));运行结果 这里先要获取到一个属性再去获取属性的修饰符 4.2获取属性的数据类型 Class clazz sno.getType();System.out.println(clazz.getName());System.out.println(---------------------);运行结果 这里要接着上面的写 4.3获取属性的名字 String name sno.getName();System.out.println(name);System.out.println(-------------------------------);运行结果 4.4给属性赋值(给属性设置值必须要有对象) Field sco cls.getField(score);Object obj cls.newInstance();sco.set(obj,98);//给obj这个对象的score属性设置具体的值这个值为98System.out.println(obj);运行结果 五、获取方法的演示与应用 //获取字节码信息Class cls Student.class;1.getMethods:获取运行时类的方法还有所有父类中的方法被public修饰 Method[] methods cls.getMethods();for(Method m:methods){System.out.println(m);}System.out.println(-----------------------);运行结果 2.getDeclaredMethods:获取运行时类中的所有方法常用 Method[] declaredMethods cls.getDeclaredMethods();for(Method m:declaredMethods){System.out.println(m);}System.out.println(-----------------------);运行结果 3.获取指定的方法 Method showInfo1 cls.getMethod(showInfo);System.out.println(showInfo1);Method showInfo2 cls.getMethod(showInfo, int.class, int.class);System.out.println(showInfo2);Method work cls.getDeclaredMethod(work);work.setAccessible(true);//这里是个重点暴力破拆私有--调用.setAccessible方法System.out.println(work);System.out.println(-----------------------);运行结果 4.调用方法 Object o cls.newInstance();myMethod.invoke(o);//调用o对象的mymethod方法work.invoke(o);//调用o对象的work方法运行结果 六、获取运行时类的接口 public static void main(String[] args) {//获取字节码信息Class cls Student.class;//获取运行时类的接口Class[] interfaces cls.getInterfaces();for(Class c:interfaces){System.out.println(c);}//得到父类的接口//先得到父类的字节码信息Class superclass cls.getSuperclass();//得到接口Class[] interfaces1 superclass.getInterfaces();for(Class c:interfaces1){System.out.println(c);}//获取运行时类所在的包Package aPackage cls.getPackage();System.out.println(aPackage);System.out.println(aPackage.getName());//获取运行类的注解Annotation[] annotations cls.getAnnotations();for(Annotation a:annotations){System.out.println(a);}}运行结果 总结 以上就是今天要分享的内容干货满满其中有一个重点在获取指定的私有方法时候暴力破拆私有的权限要不然后面调用这个方法会报错利用.setAccessible(true)方法实现看完了的话点个收藏吧防止用的时候找不到。
http://www.hkea.cn/news/14407372/

相关文章:

  • 国内建筑网站开发板有什么用
  • 外贸展示型网站建设怎样做网络推广软件系统
  • 做视频网站视频短片网站服务器选择
  • 廉江网站建设深圳公司注册地址异常怎么办
  • 邦邻营销型网站建设动漫设计作品
  • 淘宝数据网站开发效果好的网站建设
  • 网站建设的目标客户青岛wordpress建站
  • 自己做装修图网站wordpress 页面模板不显示
  • 免费 网站 平台58同城北京网站建设
  • 网站建设 猫云seo浏览器官网入口
  • 宁波市建设工程检测协会网站2144网页游戏大厅
  • 怎么给网站做缓存网页设计基础的课程介绍
  • 设计师常上的网站网站地图文件
  • py网站开发网络营销推广的成功案例
  • 珠海多语种网站制作网站跳转微信链接
  • 鹿岛建设 网站公司网站后台是什么
  • 又拍云wordpress全站cdn网页设计与网站开发项目
  • 国外优秀的平面设计网站惠州百度搜索排名优化
  • 怎么推广外贸网站永康网站建设专业公司
  • 聊城招聘网站建设企业平台有哪些
  • 平台型网站建设公司网站权重不够高 导致
  • 长沙网站建设推广怎么做填表网站
  • wordpress产品列表佛山做网站优化公司
  • 电子商务网站如何推广网站开发公司需要什么资质
  • 简述dw网站开发流程加速器怎么加速网页
  • 修改图片网站响应式网站图片代码
  • 如何做公司网站点击率高360免费建站官方
  • 精湛的企业网站建设国内最大设计网站
  • 本地佛山企业网站建设太原seo代理商
  • 网站推广网站制作网站建设公司工程公司注册费用