Java ObjectStreamClass forClass()方法与示例

news/2024/5/19 3:02:09 标签: java, jvm, python, class, 反射
class="baidu_pl">
class="article_content clearfix">
class="htmledit_views">

ObjectStreamClass类的forClass()方法 (ObjectStreamClass Class forClass() method)

  • forClass() method is available in class="w3-codespan">class="tags" href="/tags/JAVA.html" title=java>java.io package.

    class="raw_b_node">forClass()方法class="tags" href="/tags/JAVA.html" title=java>java.io包中可用。

  • forClass() method is used to return the Class in the local virtual machine that this version is associated with.

    class="raw_b_node">forClass()方法用于在与此版本关联的本地虚拟机中返回Class。

  • forClass() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    class="raw_b_node">forClass()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • forClass() method does not throw an exception at the time of returning Class.

    在返回Class时, class="raw_b_node">forClass()方法不会引发异常。

Syntax:

class="raw_b_node">句法:

class="has">    public Class forClass();

Parameter(s):

class="raw_b_node">参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

class="raw_b_node">返回值:

The return type of the method is class="w3-codespan">Class, it returns the class instance that this descriptor denotes or may returns null when there is no desired local class.

方法的返回类型为Class ,它返回此描述符表示的类实例,或者在没有所需的本地类时可以返回null。

Example:

class="raw_b_node">例:

class="has">// Java program to demonstrate the example 
// of Class forClass() method of ObjectStreamClass

import class="tags" href="/tags/JAVA.html" title=java>java.io.*;

public class ForClass {
 public static void main(String[] args) {
  // Instantiates two ObjectStreamClass for Long
  // and Calendar
  ObjectStreamClass o_stm1 = ObjectStreamClass.lookup(Long.class);
  ObjectStreamClass o_stm2 = ObjectStreamClass.lookup(String.class);

  // By using forClass() method is to return
  // the class that the version is linked to
  Class cl1 = o_stm1.forClass();
  Class cl2 = o_stm2.forClass();

  // Display cl1 and cl2
  System.out.println("o_stm1.forClass(): " + cl1);
  System.out.println("o_stm2.forClass(): " + cl2);
 }
}

Output

class="raw_b_node">输出量

class="has">o_stm1.forClass(): class class="tags" href="/tags/JAVA.html" title=java>java.lang.Long
o_stm2.forClass(): class class="tags" href="/tags/JAVA.html" title=java>java.lang.String 


翻译自: https://www.includehelp.com/class="tags" href="/tags/JAVA.html" title=java>java/objectstreamclass-forclass-method-with-example.aspx


http://www.niftyadmin.cn/n/1255729.html

相关文章

js获取18个月前和30天后的时间

获取18个月前的时间 var date new Date(); var dateDemo date.setMonth(date.getMonth()-18); var startDate new Date(dateDemo); 获取30天后的时间 var startTime new Date(); var startDate new Date(startTime); startDate.setDate(startDate.getDate() 30);转载于:ht…

Java LineNumberInputStream mark()方法与示例

LineNumberInputStream类mark()方法 (LineNumberInputStream Class mark() method) mark() method is available in java.io package. mark()方法在java.io包中可用。 mark() method is used to set the current position in this LineNumberInputStream and a subsequent call…

java日历类add方法_Java日历getFirstDayOfWeek()方法与示例

java日历类add方法日历类的getFirstDayOfWeek()方法 (Calendar Class getFirstDayOfWeek() method) getFirstDayOfWeek() method is available in java.util package. getFirstDayOfWeek()方法在java.util包中可用。 getFirstDayOfWeek() method is used to get the first day …

windows下使用svn命令行

subversion1.9.4官方下载地址:https://www.visualsvn.com/downloads/ 下载最新svn命令行工具 解压后配置环境变量:path:C:\Apache-Subversion-1.9.4\bin; 即可使用 转载于:https://www.cnblogs.com/tabCtrlShift/p/9056114.html

jsp求矩形周长和面积_C程序查找矩形的面积和周长

jsp求矩形周长和面积Input length and breadth and calculate the area and perimeter of a rectangle using C program. 输入长度和宽度,并使用C程序计算矩形的面积和周长。 Formula to calculate area of a rectangle: length * breadth 计算矩形面积的公式&…

xcode加载静态链接库.a文件总是失败

明明项目是对的,代码没有问题,并且把项目作为库项目引入到新项目中没问题,可是一旦把项目编译出.a文件,引入到新项目中不知为何会有几率出现一大堆错误,其实是xcode的缓存机制在作怪,去这个目录&#xff1a…

006_各种网页错误代码线上示例

一、跨域问题的405 随便请求一个不存在网页的返回405是由于跨域请求时nginx会先进行请求方法的判断,然后再去执行响应的方法(get,post等等的),去掉跨域后返回404 二、xxx 转载于:https://www.cnblogs.com/itcomputer/p/9061606.html

booleanvalue_Java布尔类booleanValue()方法及示例

booleanvalue布尔类booleanValue()方法 (Boolean class booleanValue() method) booleanValue() method is available in java.lang package. booleanValue()方法在java.lang包中可用。 booleanValue() method is used to return the value denoted by this Boolean object con…