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

招聘网站竞品分析怎么做怎样自己做网站卖钱

招聘网站竞品分析怎么做,怎样自己做网站卖钱,网络设计培训,如何做阿里巴巴网站目录1. 什么是反射#xff0c;为何用它2. Student类3. Person类4. 反射实现以测试学生类为主1. 什么是反射#xff0c;为何用它 1.1 什么是反射:允许程序员在程序运行期间动态的获得某个类型的信息(类本身的信息以及类的成员信息),从而开发出更为灵活通用的代码 反射能做什么… 目录1. 什么是反射为何用它2. Student类3. Person类4. 反射实现以测试学生类为主1. 什么是反射为何用它 1.1 什么是反射:允许程序员在程序运行期间动态的获得某个类型的信息(类本身的信息以及类的成员信息),从而开发出更为灵活通用的代码 反射能做什么,例如: String className “com.hr.entity.Student”; 使用上面的字符串变量值创建出其对象的对象类中的私有属性和方法如何去调用 1.2. 反射操作的前提条件: 1.2.1 获得一个类型对应的类对象 // 1. 类.classClassStudent stu Student.class;Student student new Student();// 2. 对象.getClass()Class? class1 student.getClass();try {// Class.forName(类的路径)Class? class2 Class.forName(com.lovely.reflect.Student);} catch (ClassNotFoundException e) {e.printStackTrace();}1.2.2 什么是类对象? 即Class这个类的对象,该对象就是用来描述一个类型的基本信息以及该类型中所有的成员信息 1.2.3 如何在java中获取类对象? 类.class 在编译期类型就已经定死了,但写法最简单对象.getClass()在编译期类型就已经定死了Class.forName(“类型全路径”) 写法麻烦,字符串类型容易写错,但是此写法灵活 2. Student类 java package com.lovely.reflect;import java.io.Serializable;import javax.management.RuntimeErrorException;public class Student extends Person implements Serializable {private static final long serialVersionUID 1L;private Integer id;private String name;public Integer age;public Student() {}Student(String name, Integer age) throws RuntimeErrorException, Exception {this.name name;this.age age;}public Student(Integer id, String name, Integer age) {this.id id;this.name name;this.age age;}public Integer getId() {return id;}public void setId(Integer id) {this.id id;}public String getName() {return name;}public void setName(String name) {this.name name;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age age;}void show() {String str study(odorable);System.out.println(str);}public void show(String name) {this.name name;System.out.println(我是 name);}private String study(String name) {return name 要学习。;}Overridepublic String toString() {return Student [id id , name name , age age ];}} 3. Person类 package com.lovely.reflect;public class Person {private String name;public Integer age;public Person() {this.age 100;}public String getName() {return name;}public void setName(String name) {this.name name;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age age;}void show() {}}4. 反射实现 package com.lovely.reflect;import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier;public class Test1 {public static void main(String[] args) {// testClassInfo();// testConstructor();// testCharacter();testMethod();}SuppressWarnings(rawtypes)static void testClassInfo() {// 反射得到类加载的信息Student stu new Student();Class stuClass stu.getClass();// 访问修饰符System.out.println(stuClass.getModifiers()); // 返回修饰符所对应的数字System.out.println(此类修饰符是 Modifier.toString(stuClass.getModifiers()));// 类的路径 和 类名System.out.println(stuClass.getName() \t stuClass.getSimpleName());// student所在的包名Package pkg stuClass.getPackage();System.out.println(pkg.getName());// student 的父类名Class superClass stuClass.getSuperclass();System.out.println(stu父类 superClass.getSimpleName());while (true) {if (stuClass ! null) {System.out.println(学生类的继承体系 stuClass.getName());stuClass stuClass.getSuperclass();} else {break;}}// 创建类对象try {stuClass stu.getClass();stu (Student) stuClass.newInstance();System.out.println(stu);} catch (InstantiationException e) {e.printStackTrace();} catch (IllegalAccessException e) {e.printStackTrace();}System.out.println(学生类实现的接口类型);Class[] interfaces stuClass.getInterfaces();for (Class inter : interfaces) {System.out.println(inter);}}static void testConstructor() {// 反射得到类的构造信息ClassStudent stuClass Student.class;try {// getConstructor() 只可拿到public的构造ConstructorStudent cs stuClass.getConstructor();Student stu cs.newInstance();System.out.println(stu);System.out.println(cs.getModifiers() \t cs.getName());// 拿到非public构造类cs stuClass.getDeclaredConstructor(String.class, Integer.class);// 授权访问// cs.setAccessible(true);// 用构造类创建student 对象 参数和上面对应stu cs.newInstance(小明, 19);System.out.println(stu);// 三个构造cs stuClass.getDeclaredConstructor(Integer.class, String.class, Integer.class);stu cs.newInstance(1, point, 18);System.out.println(stu);System.out.println(获得构造的参数, 返回类对象数组);cs stuClass.getDeclaredConstructor(String.class, Integer.class);// 拿到当前构造类的 构造参数Class?[] parameterTypeClass cs.getParameterTypes();for (Class? type : parameterTypeClass) {System.out.println(type);}System.out.println(获得异常);// 获得构造的异常Class?[] exTypes cs.getExceptionTypes();for (Class? exType : exTypes) {System.out.println(exType);}} catch (Exception e) { e.printStackTrace();}}static void testCharacter() {// 反射得到类的属性信息Student stu new Student();ClassStudent stuClass Student.class;try {// 通过名字获取子父类中的属性对象public子类没有 找父类Field filed stuClass.getField(age);// age属性的名称和修饰符System.out.println(filed.getName() \t Modifier.toString(filed.getModifiers()));filed.set(stu, 1);System.out.println(反射赋值age: filed.get(stu));// 通过名字获取当前类的属性对象不管什么修饰符filed stuClass.getDeclaredField(id);System.out.println(filed.getName() \t filed.getType() \t Modifier.toString(filed.getModifiers()));// 赋予可访问权限filed.setAccessible(true);filed.set(stu, 1);Object obj filed.get(stu);System.out.println(反射赋值id: obj);System.out.println();// 拿到当前类和父类的共有属性对象Field[] fs stuClass.getFields();for (Field f : fs) {System.out.println(f.getName() : f.get(stu));}System.out.println();// 拿到当前类的所有属性对象fs stuClass.getDeclaredFields();for (Field f : fs) {f.setAccessible(true);System.out.println(f.getName() : f.get(stu));}} catch (Exception e) {e.printStackTrace();} }static void testMethod() {// 反射得到类的方法信息try {Class? stuClass Class.forName(com.lovely.reflect.Student);// 获得student类指定名字和参数得方法对象 类型 getMethod只可拿到public修饰符的方法Method method stuClass.getMethod(show, String.class);System.out.println(method);// 需要学生对象调用方法 该方法的参数值method.invoke(stuClass.newInstance(), 小明);// 下面是获得任意方法对象 方法有参数要指定参数Method method1 stuClass.getDeclaredMethod(show);// 在Student类里面是私有的 在test1里面 利用反射想访问 得设置权限为truemethod1.setAccessible(true);Object result method1.invoke(stuClass.newInstance());System.out.println(方法返回值为 result);System.out.println();// study 方法对象Method method2 stuClass.getDeclaredMethod(study, String.class);// 可以调用该非public有方法method2.setAccessible(true);// 方法对象调用方法Object study method2.invoke(stuClass.newInstance(), odorable);System.out.println(study);// 方法对象的修饰符 方法名 参数返回值System.out.println(Modifier.toString(method2.getModifiers()) \t method2.getName() \t method2.getReturnType());// 参数列表类型数组Class?[] ptypes method2.getParameterTypes();for (Class? type : ptypes) {System.out.println(type);}System.out.println();// 获得当前类中所有方法对象Method[] methods stuClass.getDeclaredMethods();for (Method me : methods) {System.out.println(me.getName());} System.out.println();// 获得当前类一直到Object类中所有public方法对象 (Student Person Object)methods stuClass.getMethods();for (Method me : methods) {System.out.println(me.getName());}} catch (Exception e) {e.printStackTrace();}} } 更新…
http://www.pierceye.com/news/777832/

相关文章:

  • 三维家是在网站上做还是在app上国内新闻最新5条
  • 呼伦贝尔网站设计wordpress如何关闭主题
  • 苏州网站制作网站建设淮安住房和城乡建设厅网站
  • 房产中介网站wordpress模板mip
  • 汽车租赁网站怎么做沈阳网站开发程序员工资
  • 网站建设教程搭建汽岁湖南岚鸿专注交城有做网站的吗
  • 网站开发怎么连接sqlserver建设网站怎么收费标准
  • 万网网站模板购买北京南站核酸检测地点
  • 南京城乡建设网站公司做网站哪个好
  • 有没有学做衣服的网站广告设计公司有什么岗位
  • 什么网站做免单衣服厦门设计师网站
  • 深圳网站建设 龙华信科易乐自助建站
  • 徐老师在那个网站做发视频搜索引擎优化特点
  • 工信部网站备案批准文件重庆装修网站建设
  • 网站被攻击了怎么办网站优化 价格查询
  • 北京网站建设公司怎么样怎么做qq盗号网站
  • 中企动力网站建设合同中天建设招标网站
  • 湖南手机版建站系统开发wordpress获取用户角色
  • 南皮网站建设价格泰安房产信息网官网首页
  • 网页制作与网站建设实战大全重庆房产信息网官网
  • 上海的网站建设公司app对接网站登录要怎么做
  • 江苏省备案网站现在什么网站做外贸的最好
  • 如何知道网站是否被k蓝山网站建设
  • 网站维护服务公司免费的网站推广渠道
  • 网站建设方案应该怎么写asp网站无法上传图片
  • 建个网站多少钱app企业关键词排名优化公司
  • 电子商务他们的代表网站代码网站怎么做的
  • 如何做网站卖东西长春互联网公司排名
  • 怎样拥有自己的网站制作网站的步骤和方法
  • 北京电子商务app网站建设大兴小程序源码如何部署到服务器