Class中的cast方法(强制转换)
来源:互联网 发布:扑克游戏源码 编辑:程序博客网 时间:2024/06/05 21:09
Class中的方法源码:
public T cast(Object obj) { if (obj != null && !isInstance(obj)) throw new ClassCastException(cannotCastMsg(obj)); return (T) obj;}
测试代码:
@Testpublic void testCast() { Object worker = new Worker(); //cast方法是就是将参数worker强制转换为其对应的类型 //以下两种方法作用相同 Worker worker1 = Worker.class.cast(worker); Worker worker2 = (Worker)worker; System.out.println(worker1.getCountry());}
阅读全文
0 0
- Class中的cast方法(强制转换)
- c指针的强制转换(cast)
- cast : 强制转换类型
- cast强制类型转换
- C++中的四种强制类型转换cast(显式转换)
- C++中的强制类型转换(cast)——static_cast, dynamic_cast, const_cast和reinterpret_cast
- Item09. 强制转换(New Cast Operators)
- C++中四种cast类型强制转换方式
- JAVA int 强制类型转换错误提示(Cannot cast from Object to int)
- JAVA int 强制类型转换错误提示(Cannot cast from Object to int)
- JAVA int 强制类型转换错误提示(Cannot cast from Object to int)
- (读书笔记)C++中的强制类型转换
- JAVA中的强制转换
- C++中的强制转换
- c++中的强制转换
- C++ 中的cast(显式类型转换)
- C++ 中的 cast(显式类型转换)
- C++ 中的 cast(显式类型转换)
- java 文件上传时候报错 FileItemStream$ItemSkippedException
- svn:Checksum mismatch while updating
- recyclerview嵌套scrollview滑动卡顿的问题
- linux 下的mount
- 抓取URl数据方法
- Class中的cast方法(强制转换)
- awk用法
- How to Install Eclipse IDE with C/C++ and Qt V4.7.2 (OpenGL included)
- 序列化二叉树(Java实现)
- CetnOS7.0安装配置Kafka集群
- python连接mysql/Oracle及读取数据库内容
- 在网站布局中在某些屏幕中显示几列 布局步骤
- 简单学生系统之学生基本信息
- Nginx配置文件nginx.conf详解