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

幼教网站建设分析wordpress 添加表格

幼教网站建设分析,wordpress 添加表格,网站开发和网络开发区别,网站制作案例价格1、获取Class对象的三种方式 1、对象调用Object类的getClass()方法#xff08;对象.getClass()#xff09; 2、调用类的class属性#xff08;类名.class#xff09; 3、调用Class类的静态方法#xff08;Class.forName(“包名.类名”)#xff09;常用 Student类 package…1、获取Class对象的三种方式 1、对象调用Object类的getClass()方法对象.getClass() 2、调用类的class属性类名.class 3、调用Class类的静态方法Class.forName(“包名.类名”)常用 Student类 package com.example.reflection;public class Student { }测试类 public class Demo {public static void main(String[] args) {//对象调用父类Object的getClass()方法Student student new Student();Class? extends Student clazz student.getClass();System.out.println(clazz);//调用类的class属性ClassStudent stu Student.class;System.out.println(stu);//调用Class类的静态方法forName()向方法中传一个字符串包名.类名try {Class? c Class.forName(com.example.reflection.Student);System.out.println(c);} catch (ClassNotFoundException e) {throw new RuntimeException(e);}} }运行结果 2、获取构造方法 1、getConstructors() 获取被public修饰构造方法 2、getDeclaredConstructors() 获取所有构造方法包括private、protected、默认、public 3、getConstructor(参数类型…) 获取单个被public修饰构造方法 参数类型为可变参数有几个参数就写几个值为null时表示获取无参构造 4、getDeclaredConstructor(参数类型…) 根据参数类型获取单个构造方法包括private、protected、默认、public参数类型同getConstructor一样 5、setAccessible(true) Constructor对象调用该方法 暴力访问该方法忽略掉所有访问修饰符 Student类 package com.example.reflection;public class Student {/*** 默认构造方法** param str 形参*/Student(String str) {System.out.println(默认构造方法执行了...);}/*** 无参构造方法*/public Student() {System.out.println(无参构造方法执行了...);}/*** 一个参数的构造方法** param age 年龄*/public Student(int age) {System.out.println(年龄 age);}/*** 多参构造方法** param name 姓名* param age 年龄* param password 密码*/public Student(String name, int age, String password) {System.out.println(姓名 name 年龄 age 密码 password);}protected Student(boolean n) {System.out.println(受保护的构造方法执行了... n);}/*** 私有构造方法** param sex 性别*/private Student(char sex) {System.out.println(私有构造方法执行了... sex);} } 测试类 public class Demo {public static void main(String[] args) {try {//加载Class对象Class? clazz Class.forName(com.example.reflection.Student);//获取所有公有构造方法Constructor?[] constructors clazz.getConstructors();System.out.println(公有构造方法);System.out.println(Arrays.toString(constructors));System.out.println();constructors clazz.getDeclaredConstructors();System.out.println(所有构造方法包括私有、受保护、默认和公有);System.out.println(Arrays.toString(constructors));System.out.println();System.out.println(公有无参构造方法);Constructor? con clazz.getConstructor(null);System.out.println(con);System.out.println();con clazz.getConstructor(int.class);System.out.println(公有有参构造方法);System.out.println(con);System.out.println();con clazz.getDeclaredConstructor(char.class);System.out.println(私有有参构造方法);System.out.println(con);System.out.println();System.out.println(暴力访问忽略掉访问修饰符);Constructor? c clazz.getDeclaredConstructor(char.class);c.setAccessible(true);c.newInstance(男);} catch (Exception e) {throw new RuntimeException(e);}} }运行结果 3、获取成员变量并调用 1、getFields() 获取所有被public修饰字段 2、getDeclaredFields() 获取所有字段包括private、protected、默认、public 3、getField(字段名) 根据字段名获取被public修饰字段 4、getDeclaredField(字段名) 根据字段名获取字段包括private、protected、默认、public所修饰的字段 Student package com.example.reflection;public class Student {public int height;double weight;private String name;private int age;private char sex;private String password;/*** 无参构造方法*/public Student() {System.out.println(无参构造方法执行了...);} }测试类 public class Demo {public static void main(String[] args) {try {Class? clazz Class.forName(com.example.reflection.Student);Field[] fields clazz.getFields();System.out.println(获取所有公有的字段);System.out.println(Arrays.toString(fields));System.out.println();fields clazz.getDeclaredFields();System.out.println(获取所有字段包括私有、受保护、默认和公有);System.out.println(Arrays.toString(fields));System.out.println();System.out.println(获取公有的字段并赋值);Field height clazz.getField(height);System.out.println(身高 height);Object obj clazz.getConstructor().newInstance();height.set(obj, 180);Student stu (Student) obj;System.out.println(学生身高 stu.height cm);System.out.println();System.out.println(获取默认字段并赋值);Field weight clazz.getDeclaredField(weight);System.out.println(体重 weight);weight.set(obj, 82.5);System.out.println(学生体重 stu.weight kg);} catch (Exception e) {throw new RuntimeException(e);}} }运行结果 4、获取成员方法并调用 1、getMethods() 获取所有被public所修饰的成员方法 2、getDeclared() 获取所有成员方法包括private、protected、默认、public 3、getMethod(方法名称,方法参数…) 根据方法名称、参数获取被public修饰的方法 4、getDeclaredMethod(方法名称,方法参数…) 根据方法名称、参数获取默认、被protected修饰的方法 5、Method中的invoke(对象,参数值…)可以执行方法若要执行被private修饰的方法需要设置Method对象.setAccessible(true)解除私有限定 Student package com.example.reflection;public class Student {/*** 无参构造方法*/public Student() {System.out.println(无参构造方法执行了...);}public void test1(String str) {System.out.println(调用了公有的、String参数的方法 str ...);}protected void test2() {System.out.println(调用了受保护的、无参的方法test2...);}void test3() {System.out.println(调用了默认的、无参的方法test3...);}private static String test4(int age) {System.out.println(调用了私有的、有参、有返回值的方法test4... age);return test4的返回值;} }测试类 public class Demo {public static void main(String[] args) {try {Class? clazz Class.forName(com.example.reflection.Student);Method[] methods clazz.getMethods();System.out.println(获取所有公有的成员方法);System.out.println(Arrays.toString(methods));System.out.println();methods clazz.getDeclaredMethods();System.out.println(获取所有成员方法包括私有、受保护、默认和公有);System.out.println(Arrays.toString(methods));System.out.println();Method test1 clazz.getMethod(test1, String.class);System.out.println(test1);Object obj clazz.getConstructor().newInstance();test1.invoke(obj, test1);System.out.println();Method test3 clazz.getDeclaredMethod(test3);System.out.println(test3);test3.invoke(obj);System.out.println();Method test4 clazz.getDeclaredMethod(test4, int.class);System.out.println(test4);test4.setAccessible(true); //解除私有限定Object result test4.invoke(obj, 15);System.out.println(返回值 result);} catch (Exception e) {throw new RuntimeException(e);}} }5、获取main方法并执行 Student package com.example.reflection;public class Student {public static void main(String[] args) {System.out.println(Student中的main方法执行了...);} }测试类 public class Demo {public static void main(String[] args) {try {//1、获取Student的字节码文件Class? clazz Class.forName(com.example.reflection.Student);//2、获取main方法Method main clazz.getMethod(main, String[].class);//3、调用main方法// 第一个参数对象类型因为方法时静态的所有为null可以// 第二个参数String数组这里要注意在JDK1.4之后是数组JDK1.5之后为可变参数// 这里拆的时候将new String[]{a,b,c}拆成3个对象所有需要强制转换main.invoke(null, (Object) new String[]{a, b, c}); // main.invoke(null,new Object[]{new String[]{a,b,c}}); //这样也可以} catch (Exception e) {throw new RuntimeException(e);}} }运行结果 6、通过反射运行配置文件内容 ​ 利用反射和配置文件可以使应用程序更新时对源码无需进行修改只需将类发送给客户端修改配置文件即可 application.properties classnamecom.example.reflection.Student methodNametest3Student package com.example.reflection;public class Student {/*** 无参构造方法*/public Student() {System.out.println(无参构造方法执行了...);}public void test1(String str) {System.out.println(调用了公有的、String参数的方法 str ...);} }测试类 public class Demo {public static void main(String[] args) {Properties prop new Properties();InputStream is Thread.currentThread().getContextClassLoader().getResourceAsStream(application.properties);try {prop.load(is);//获取类String classname prop.getProperty(classname);Class? clazz Class.forName(classname);//获取方法名String methodName prop.getProperty(methodName);Method test2 clazz.getDeclaredMethod(methodName);test2.invoke(clazz.getConstructor().newInstance());} catch (Exception e) {throw new RuntimeException(e);}} }运行结果 7、通过反射越过泛型检查 需求有一个List list,向其中添加Integer类型的数据 测试类 public class Demo {public static void main(String[] args){ListString list new ArrayList();list.add(aaa);list.add(bbb);//获取ArrayList的Class对象反向调用add()方法Class? extends List clazz list.getClass();try {Method add clazz.getMethod(add, Object.class);add.invoke(list, 13);} catch (Exception e) {throw new RuntimeException(e);}for (Object obj : list) {System.out.println(obj);}} }运行结果
http://www.hkea.cn/news/14293629/

相关文章:

  • 工作室网站模板新东方烹饪培训学校
  • 做网站内容岳阳市网页设计人才网
  • 国外比较有名的设计工作室网站asp.net网站安装顺序
  • 山东众德建设项目管理公司网站专业网架加工
  • 手绘风网站揭阳建设网站
  • wordpress投稿上传图片泽成杭州seo网站推广排名
  • 几台服务器做集群网站紫金论坛最新新闻事件
  • 做网站的公司跑了台州椒江找人做网站
  • 大兴网站建设优化seo惠济郑州网站建设
  • 网站建设售后服务方案免费公司网站模板
  • 手机建站源码巩义企业网站托管代运营公司
  • 免费网站封装apphtml网站建设中
  • 南京溧水城市建设集团网站wordpress更改固定链接后无法登陆
  • 做网站需要多大的显存石家庄网站托管
  • 建设网站的主要流程有哪些内容互联网行业都有哪些专业
  • 青海做高端网站建设的公司WordPress导航条之间得跳转
  • 南昌网站建设 南昌做网站公司图文广告设计公司
  • 注册 网站开发 公司深圳 网站建设设计
  • wordpress网站和微信公众号广东省网站设计与开发
  • 您有新信息 建设招标网官方网站临汾推广型网站开发
  • 途牛网站开发需求360渠道推广系统
  • 最好的网站设计重庆网站建设 夹夹虫
  • 网站出租建设做同业业务一般关注哪些网站
  • 做一个app成本济南网站优化收费标准
  • 佛山网站设计培训深圳品牌型网站建设
  • 网站建设图片怎么调网站开发计划书网站技术解决方案
  • 网站开发的背景是指什么软件沈阳小程序开发报价
  • 卖域名的网站要怎么做兼容性视图中显示所有网站
  • 受欢迎的建网站哪家好怎么从网上找客户
  • 网站建设与管理专业工资高吗tcn短网址在线生成