assubclass_Java类class asSubclass()方法及示例

assubclass

类类asSubclass()方法 (Class class asSubclass() method)

  • asSubclass() method is available in java.lang package.

    asSubclass()方法在java.lang包中可用。

  • asSubclass() method casts this Class object to denote a subclass of the class denoted by the given Class object.

    asSubclass()方法强制转换此Class对象,以表示由给定Class对象表示的类的子类。

  • asSubclass() 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.

    asSubclass()方法是一个非静态方法,只能由类对象访问,如果尝试使用类名访问该方法,则会收到错误消息。

  • asSubclass() method may throw ClassCastException at the time of casting a Class.

    asSubclass()方法可能会在强制转换Class时引发ClassCastException。

    ClassCastException: In this exception when this Class does not denote a subclass of the given class.

    ClassCastException:在此异常中,当此Class类不表示给定类的子类时。

Syntax:

句法:

    public Class asSubclass(Class class_name);

Parameter(s):

参数:

  • Class class_name – represents the name of the class.

    类class_name –表示类的名称。

Return value:

返回值:

The return type of this method is Class, it returns this Class object, cast to denote a subclass of the given Class object.

此方法的返回类型为Class ,它返回此Class对象,强制转换为表示给定Class对象的子类。

Example:

例:

// Java program to demonstrate the example 
// of Class asSubclass (Class class_name) method of Class class
public class ParentClass {
public static void main(String[] args) throws Exception {
// Creating ParentClass and ChildClass instance
ParentClass pc = new ParentClass();
ParentClass cc = new ChildClass();
// Get Classname
Class parent = pc.getClass();
System.out.println("Parent Class: " + parent);
Class child = cc.getClass();
System.out.println("Child Class: " + child);
// We are denoting ChildClass of the given ParentClass object
Class subclass = child.asSubclass(parent);
System.out.println("child.asSubclass(parent): " + subclass);
}
}
class ChildClass extends ParentClass {
}

Output

输出量

Parent Class: class ParentClass
Child Class: class ChildClass
child.asSubclass(parent): class ChildClass

翻译自: https://www.includehelp.com/java/class-class-assubclass-method-with-example.aspx

assubclass

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/379103.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

VB6.0 怎样启用控件comdlg32.ocx

VB6.0 怎样启用控件comdlg32.ocx 怎样启用控件comdlg32.ocx 2008-10-08 09:32 提问者: nefu_20061617 |浏览次数:1502次vbs文件中有代码Set ComDlg CreateObject("MSComdlg.CommonDialog")运行时发生错误ActiveX 部件不能创建对象: MSComdlg.…

Python---爬虫案例

例1、爬取公众号文章中的图片。 1,首先打开要获取公众号文章的地址 2,按下F12,再按Ctrl Shift C,然后鼠标移动到图片位置,然后观察控制台中显示图片对应的代码位置 3,分析该位置的代码段 代码段如下&…

WinCE驱动开发问题精华集锦(二)

转自:http://hgh123.blog.163.com/blog/static/5980422120086183115543/ 感谢 我怎么能在PB左边的定制平台加进我的驱动呢? 两种办法: 1、在platform.bib或者project.bib的MODULES部分添加一条语句,例如: MyDriver.dll…

报错Unable to resolve target android-5

报错信息:Error:Unable to resolve target android-X(X是一个数字) 错误分析:这种错误一般大部分是SDK 版本不符所造成的,一般会在Ecplise工作空间导入项目时候出现此错误,一般提示:Error:Unabl…

matlab盒子分形维数_分形维数--matlab

一维曲线分形维数的matlab程序function DFractalDim(y,cellmax)%求输入一维信号的计盒分形维数%y是一维信号%cellmax:方格子的最大边长,可以取2的偶数次幂次(1,2,4,8...),取大于数据长度的偶数%D是y的计盒维数(一般情况下D>1),Dlim(log(N(e))/log(k/e)),if cellmaxerror(cel…

Java布尔类toString()方法及示例

Syntax: 句法: public String toString();public static String toString(boolean value);布尔类toString()方法 (Boolean class toString() method) toString() method is available in java.lang package. toString()方法在java.lang包中可用。 toString() metho…

pcm数据编码成为aac格式文件(可以在酷狗播放)

pcm数据编码成为aac格式文件&#xff08;可以在酷狗播放&#xff09; 关于其中的aac adts格式可以参考&#xff1a;AAC ADTS格式分析 main.c #include <stdio.h> #include <stdlib.h> #include <stdlib.h>#include <libavcodec/avcodec.h> #include …

Python---实验九

1、使用标准库urllib爬取“http://news.pdsu.edu.cn/info/1005/31269.htm”平顶山学院新闻网上的图片&#xff0c;要求:保存到F盘pic目录中&#xff0c;文件名称命名规则为“本人姓名” “_图片编号”&#xff0c;如姓名为张三的第一张图片命名为“张三_1.jpg”。 from re imp…

Request.Url学习(转)

原文地址&#xff1a;http://www.cnblogs.com/jame-peng1028/articles/1274207.html?login1#commentform 网址&#xff1a;http://localhost:1897/News/Press/Content.aspx/123?id1#tocRequest.ApplicationPath/Request.PhysicalPathD:\Projects\Solution\web\News\Press\Con…

32接上拉5v_51单片机P0口上拉电阻的选择

作为I/O口输出的时候时&#xff0c;输出低电平为0 输出高电平为高组态(并非5V&#xff0c;相当于悬空状态&#xff0c;也就是说P0 口不能真正的输出高电平)。给所接的负载提供电流&#xff0c;因此必须接(一电阻连接到VCC)&#xff0c;由电源通过这个上拉电阻给负载提供电流。P…

[转载]FPGA/CPLD重要设计思想及工程应用(时序及同步设计)

来源&#xff1a;http://www.eetop.cn/blog/html/11/317611-13412.html 数字电路中,时钟是整个电路最重要、最特殊的信号。 第一, 系统内大部分器件的动作都是在时钟的跳变沿上进行, 这就要求时钟信号时延差要非常小, 否则就可能造成时序逻辑状态出错. 第二, 时钟信号通常是系统…

duration java_Java Duration类| ofMinutes()方法与示例

duration javaDuration Class of Minutes()方法 (Duration Class ofMinutes() method) ofMinutes() method is available in java.time package. ofMinutes()方法在java.time包中可用。 ofMinutes() method is used to represent the given minutes value in this Duration. of…

实验五 图形设计

每复制一个方法都要绑定Paint事件 一、创建Windows窗体应用程序&#xff0c;要求如下&#xff1a;&#xff08;源代码运行界面&#xff0c;缺少任一项为0分&#xff0c;源代码只需粘贴绘制图形代码所在的方法&#xff0c;不用粘贴太多&#xff09; 例如: &#xff08;1&…

yuv编码成h264格式写成文件

yuv编码成h264格式写成文件 &#xff08;使用ffmpeg 编码yuv420p编码成h264格式&#xff09; #include <stdio.h> #include <stdlib.h> #include <stdint.h>#include <libavcodec/avcodec.h> #include <libavutil/time.h> #include <libavut…

c++ stl队列初始化_声明,初始化和访问向量| C ++ STL

c stl队列初始化Here, we have to declare, initialize and access a vector in C STL. 在这里&#xff0c;我们必须声明&#xff0c;初始化和访问C STL中的向量。 向量声明 (Vector declaration) Syntax: 句法&#xff1a; vector<data_type> vector_name;Since, vec…

ADO.NET与SQL Server数据库的交互

7.3.1 使用SqlConnection对象连接数据库 例如&#xff1a;建立与SQL Server数据库的连接。 string connstring"Data Sourceservername;uidusername;pwdpassword;Initial Catalogdbname";SqlConnection connnew SqlConnection(connstring);conn.Open(); 例如&#xf…

nsis 修改exe执行权限

通过修改注册表的方式&#xff0c;修改exe的执行权限。&#xff0c;以下例子是使用管理员运行。 ;添加admin权限 SectionWriteRegStr HKCU "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" "$INSTDIR\spp.exe" "RUNASADMIN&qu…

linux ftp日志_linux学习笔记(一)——Linux分区和目录结构

linux学习笔记&#xff08;一&#xff09;——Linux分区和目录结构安装Linux时&#xff0c;手动挂载分区的情况下&#xff0c;/ 和 swap 是必须要挂载的&#xff0c;其他/home、/boot 等可以根据需要自行挂载。一般来说&#xff0c;简单的话&#xff0c;建议挂载三个分区&#…

C#通过VS连接MySQL数据库实现增删改查基本操作

创建一个数据库wsq 里面有一张beyondyanyu表 表里面有id(int)、names(varchar)、count(int)、passwords(varchar) 数据可以自己添 1、导入MySQL引用&#xff0c;你需要从官网或者其他地方下载&#xff0c;私聊我也可以 using MySql.Data.MySqlClient; 2、创建MySqlConnection对…

使用ffmpeg的filter处理yuv数据包括split filter(分流)、crop filter(裁剪)、vflip filter(垂直向上的翻转)、overlay filter(合成)

使用ffmpeg的filter处理yuv数据包括split filter(分流)、crop filter(裁剪)、vflip filter(垂直向上的翻转)、overlay filter(合成) #include <stdio.h>#include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libavfilter/avfil…