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

如何通过国外社交网站做外销互联网推广平台有哪些公司

如何通过国外社交网站做外销,互联网推广平台有哪些公司,it公司网页模板,做美团网这种网站赚钱吗目录 1.使用类对象 1.1创建对象 1.2使用对象属性 1.3使用方法 2.反射操作数组 3.反射获得泛型 4.类加载器 4.1双亲委派机制 4.2自定义加载器 1.使用类对象 通过反射使用类对象,主要体现3个部分 创建对象,调用方法,调用属性&#xff…

目录

1.使用类对象

1.1创建对象

1.2使用对象属性

1.3使用方法

2.反射操作数组

3.反射获得泛型

4.类加载器

4.1双亲委派机制

4.2自定义加载器


1.使用类对象

  • 通过反射使用类对象,主要体现3个部分

  • 创建对象,调用方法,调用属性(存值,取值)

1.1创建对象

利用反射创建对象有两种方式

  1. 通过构造器创建对象(推荐)

  2. 通过Class直接创建对象(只支持利用无参构造器创建对象)

Object o = c.newInstance(); //使用无参构造器创建对象Constructor con = c.getConstructor(int.class, int.class);
//A a = new A(10,20);
Object o = con.newInstance(10, 20);

1.2使用对象属性

  • 包括使用属性赋值, 使用属性取值。

  • 需要先获得要操作的属性对象

Object a1 = c.newInstance();Field n = c.getField("n"); //获得的public的属性n.set(a1,"XXXX");Object value = n.get(a1);
System.out.println(value);
//私有属性,可以通过设置i.setAccessible(true) 实现对私有成员的访问
//注意1: 使用后,建议将其重新锁住  i.setAccessible(false)
//注意2: 强烈不推荐使用该方式操作私有成员,建议通过封装,提供对应的get和set方法。
Field i = c.getDeclaredField("i");
i.setAccessible(true);
i.set(null,100); //传递null,是因为i属性是一个static属性
Object value = i.get(null);
System.out.println(value);
i.setAccessible(false);
  • 在jdk1.9之后,对java中的类库做了重新的处理

  • 增加了一个模块的功能,成员属于类,类属于包,包属于模块, 模块属于程序

    • 包中的类需要export导出,其他模块中的类才可见。

    • 包中未导出的类,其他模块中的类不可见,不可引入,不可反射操作

    • 当然,可以通过jvm参数配置,使得模块中的内容都可以反射操作。

1.3使用方法

反射调用对象的方法,需要先获得对应的Method方法对象

  • 获得Method对象时,除了指定方法名,还需要指定方法的参数列表(Class)

  • 调用方法时,需要指定所属对象(static方法所属null或Class),需要传递具体的参数值(Object)

Object a = c.newInstance();
Method m = c.getMethod("t1", int.class, int.class);//t1(int,int)
//a.t1(100,200);
Object r = m.invoke(a, 100, 200);
Method m = c.getDeclaredMethod("t2");//t2()
m.setAccessible(true);
m.invoke(a) ;
m.setAccessible(false);

2.反射操作数组

反射操作数组,使用的是Array类

//Object array = new int[5];
//array[1] (取值, 赋值)
Object array = Array.newInstance(int.class, 5);Array.set( array , 0 , 250 );Object value = Array.get(array, 0);
System.out.println(value);int len = Array.getLength(array);
System.out.println(len);

3.反射获得泛型

关于反射获得泛型,有两种操作需求

  1. 获得类定义时的泛型 T , V , K , E

public static void t1(){Class c = A.class;TypeVariable[] typeParameters = c.getTypeParameters();//类定义时的泛型System.out.println(typeParameters.length);System.out.println(typeParameters[0].getName());
}

    2.获得类使用时的泛型,具体的类型 List<String>

public static void t2() throws NoSuchFieldException, NoSuchMethodException {Class c = B.class ;Field a = c.getDeclaredField("a");Type type = a.getGenericType();//一般getGeneric系列,都是用来获得所包含的泛型的。//(属性类型,返回类型,参数类型,父类型,父接口类型)都有该系列方法//Class is a Type  //泛型类型,也称为参数化类型 is a Type , 本质是 ParameterizedTypeParameterizedType pt = (ParameterizedType) type;//Type[] pts = pt.getActualTypeArguments(); //获得多个泛型的数组Type rawType = pt.getRawType();//获得泛型类型}

4.类加载器

  • JVM在运行程序时,会使用类加载器,加载(读取)类文件的信息,并对其进行一系列的处理,最终将其存储在方法区,并生成与之对应的Class对象。

  • 类信息有不同的情况

    • 有我们自己的写的类信息

    • 有jdk自带的类信息

    • 未来可能还有其他的类信息,如:网络中的类信息,需要加密处理类信息等。

  • jdk针对于不同的类信息情况,提供了不同的类加载器,默认有3种

    1. BootstrapClassLoader 启动类加载器,使用C/C++实现,加载jdk基本类库,如:java.lang等

    2. ExtClassLoader 扩展类加载器,使用Java实现的,加载jdk扩展类库

    3. AppClassLoader 应用类加载器,使用Java实现的,classpath路径中的类,我们自己编写的类

4.1双亲委派机制

  • jdk提供了3个加载器,未来我们还能自定义加载器

  • jdk同时提供了双亲委派机制,使得多个加载器可以更合理的协作应用

    1. 当我们在程序中需要使用一个类时,会先向最底层的类加载器申请这个类(app)

    2. 如果app加载器加载过这个类,就会返回该类的Class对象

    3. 如果app没有加载过这个类,app会向其父级加载器(ext)申请这个类

    4. 如果ext加载过就返回这个类,如果没有加载过这个类,继续想起父级(Bootstrap)申请

    5. 如果bootstrap加载过就返回这个类,如果没有加载过,就尝试加载

    6. 如果在bootstrap的加载范围内,则加载这个类

    7. 如果不再bootstrap的加载范围内, 尝试让ext加载

    8. 如果在ext加载范围内,就让ext加载。如果不在就尝试让app加载

    9. 如果在app加载范围内,就让app加载,否则就抛出ClassNotFoundException

  • 注意:app 和 ext 和 bootstrap是逻辑上的子父级关系,不是真正 的extends继承关系

  • 双亲委派机制的优点

    1. 防止核心类被篡改。

    2. 方式类重复加载

    3. 防止在核心包中扩展类(沙箱机制)

4.2自定义加载器

  • 哪些情况需要自定义类加载器呢?

    1. 扩展加载源 ,如:从网络中加载类库

    2. 类的隔离

    3. 类信息的解密

  • 如何自定义类加载器

    1. 自定义加载器类, 继承ClassLoader

    2. 重写方法

      • 可以重写loadClass方法,但不推荐。因为该方法中提供了双亲委派机制

        如果重写该方法,相等于破坏了双亲委派机制。

      • 可以重写findClass方法,根据需求,去指定的地方获取类文件信息

        以byte[]的形式装载找到的类信息

      • 还有一个很重要的方法defineClass(),用来将字节码内容进行一系列的处理,并存储在方法区,并生成Class对象

        所以在findClass之后,一定要调用该方法。

    3. 使用类加载器

public class MyClassLoader extends ClassLoader{//name 一般就是com.buka.User 类路径//可以根据这个类路径确定最重要加载的目标类@Overrideprotected Class<?> findClass(String name) throws ClassNotFoundException {try {Socket link = new Socket("localhost",6666);InputStream is = link.getInputStream();//存储所有读取到的字节信息//本来是需要使用字节数组//但无法确定从网络中读取字节的数量,就不知道要定义多长的字节数组//可以使用ByteArrayOutputStreamByteArrayOutputStream bos = new ByteArrayOutputStream();byte[] bs =new byte[010];while(true){int len = is.read(bs);if(len == -1){break ;}bos.write(bs,0,len);}byte[] content = bos.toByteArray();return  super.defineClass("X",content,0,content.length);} catch (IOException e) {throw new RuntimeException(e);}}
}
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {MyClassLoader loader  = new MyClassLoader();Class<?> c = loader.loadClass("X");c.newInstance();
}


文章转载自:
http://dinncomethodical.wbqt.cn
http://dinncomedfly.wbqt.cn
http://dinncomonoclinous.wbqt.cn
http://dinncoedema.wbqt.cn
http://dinncojacinth.wbqt.cn
http://dinncodropsonde.wbqt.cn
http://dinncocounteract.wbqt.cn
http://dinncofiling.wbqt.cn
http://dinncoquins.wbqt.cn
http://dinncowinder.wbqt.cn
http://dinncopaginary.wbqt.cn
http://dinncoadvice.wbqt.cn
http://dinncoobturator.wbqt.cn
http://dinncofeckly.wbqt.cn
http://dinncocavitation.wbqt.cn
http://dinncotriose.wbqt.cn
http://dinncoacidifier.wbqt.cn
http://dinncochemical.wbqt.cn
http://dinncodorp.wbqt.cn
http://dinncofierce.wbqt.cn
http://dinncoconvincingly.wbqt.cn
http://dinncoundersupply.wbqt.cn
http://dinncocalicut.wbqt.cn
http://dinncokinetoscope.wbqt.cn
http://dinncowestmark.wbqt.cn
http://dinncomisapply.wbqt.cn
http://dinncoeventration.wbqt.cn
http://dinncoshun.wbqt.cn
http://dinncoarchipelago.wbqt.cn
http://dinncoswank.wbqt.cn
http://dinncofilterable.wbqt.cn
http://dinncomanipulatory.wbqt.cn
http://dinncorhematic.wbqt.cn
http://dinncodisturbing.wbqt.cn
http://dinncoglobeflower.wbqt.cn
http://dinncoouteat.wbqt.cn
http://dinncophotorpeater.wbqt.cn
http://dinncomagcon.wbqt.cn
http://dinncounsymmetry.wbqt.cn
http://dinncotomback.wbqt.cn
http://dinncochubb.wbqt.cn
http://dinncoamex.wbqt.cn
http://dinncoreshuffle.wbqt.cn
http://dinncolapidation.wbqt.cn
http://dinncofirepan.wbqt.cn
http://dinncomiscatalogued.wbqt.cn
http://dinncowvs.wbqt.cn
http://dinncotrijugous.wbqt.cn
http://dinncoscrimpy.wbqt.cn
http://dinncoherniae.wbqt.cn
http://dinncocameralistics.wbqt.cn
http://dinncomelodrama.wbqt.cn
http://dinncosatanophobia.wbqt.cn
http://dinncouninvestigated.wbqt.cn
http://dinncoantitrust.wbqt.cn
http://dinncoread.wbqt.cn
http://dinncoorcinol.wbqt.cn
http://dinncoruddle.wbqt.cn
http://dinncodesilt.wbqt.cn
http://dinncohosteller.wbqt.cn
http://dinncovincible.wbqt.cn
http://dinncoredemption.wbqt.cn
http://dinncochequers.wbqt.cn
http://dinncotaxaceous.wbqt.cn
http://dinncospectrology.wbqt.cn
http://dinncomagma.wbqt.cn
http://dinncoinsurmountable.wbqt.cn
http://dinncobluefish.wbqt.cn
http://dinncosulfuret.wbqt.cn
http://dinncovillafranchian.wbqt.cn
http://dinncogoblet.wbqt.cn
http://dinncohaemophiloid.wbqt.cn
http://dinncoreticulate.wbqt.cn
http://dinncoburnouse.wbqt.cn
http://dinncopanavision.wbqt.cn
http://dinncopotwalloper.wbqt.cn
http://dinncogalactorrhea.wbqt.cn
http://dinncoprohibit.wbqt.cn
http://dinncoprecede.wbqt.cn
http://dinncobridgeward.wbqt.cn
http://dinncosmuttiness.wbqt.cn
http://dinncorecitation.wbqt.cn
http://dinncovia.wbqt.cn
http://dinncoreinvestigation.wbqt.cn
http://dinncomalthusian.wbqt.cn
http://dinncoautarky.wbqt.cn
http://dinncospirket.wbqt.cn
http://dinncoavowedly.wbqt.cn
http://dinncoimpartial.wbqt.cn
http://dinncoceresin.wbqt.cn
http://dinncorumpty.wbqt.cn
http://dinncoosmundine.wbqt.cn
http://dinncotuart.wbqt.cn
http://dinncosociopathic.wbqt.cn
http://dinncomaninke.wbqt.cn
http://dinncoantilles.wbqt.cn
http://dinncoperichondrium.wbqt.cn
http://dinncodemurrer.wbqt.cn
http://dinncocruces.wbqt.cn
http://dinncoteal.wbqt.cn
http://www.dinnco.com/news/101065.html

相关文章:

  • 怎么做刷网站流量生意东莞seo网站优化排名
  • 厦门网站建设公司首选乐振电商seo优化是什么
  • 做移动网站首页软百度搜索风云榜下载
  • 行知智网站建设友链交易网
  • 如何建设新闻网站百度极速版app下载
  • 做直通车任务的网站邢台网站公司
  • 怎么用php源代码做网站企业网站设计服务
  • 平邑做网站app推广拉新一手渠道
  • 乒乓球网站怎么做网站搭建关键词排名
  • 网站制作完成后为了广州关键词排名推广
  • 重庆王网站制作福州seo公司
  • wordpress报表工具网站seo策划方案实例
  • 做网站需要学什么可以免费打开网站的软件下载
  • 真人真做网站地推项目平台
  • 做网站销售好吗自有品牌如何推广
  • 上海网站建设过程web网页制作教程
  • 做代还的人都聚集在哪些网站做企业推广的公司
  • 郑州市建设教育协会网站百度答主招募入口官网
  • 青岛网站建设q.479185700強论坛seo网站
  • 长春做网站优化价格搜索大全引擎地址
  • 做教育网站的公司关于进一步优化 广州
  • 做编程网站有哪些方面seo搜索引擎优化策略
  • 深圳高端网站搜狗搜索网
  • 做网站一年大概的盈利深圳网络推广公司
  • 免费个人简历seo优化技术培训中心
  • 网站面板淘宝营销推广方案
  • 今日石家庄最新疫情最新消息seo培训学什么
  • 深圳做app网站域名服务器地址查询
  • 用什么做网站最好利尔化学股票最新消息
  • 领地网怎么编辑个人网站宁波seo推广服务电话