Q1.jvm里是不是本来就装载了primitive types的class object?
Q2.int.class.newInstance()得到的是什么类?
为什么下面这段代码什么都没打印出
Class cl;
try {
cl = int.class;
Object m = cl.newInstance();
System.out.println(m.getClass().getName());
}catch(Exception e){ }大家一起看看
Q2.int.class.newInstance()得到的是什么类?
为什么下面这段代码什么都没打印出
Class cl;
try {
cl = int.class;
Object m = cl.newInstance();
System.out.println(m.getClass().getName());
}catch(Exception e){ }大家一起看看
解决方案 »
- 在一个页面中按JButton生成JTable
- java JdbcTemplate 的方法
- 为什么向objectoutputstream写入对象,文件里却啥也没有,急死我了,各位大侠帮忙看看
- Eclipse 教程中SWT Application运行出错?
- 怎么在一个按钮里面判断曾经点过哪个按钮呢???50分求
- 在tomcat中能否将server.xml中配置的连接池(数据源)提到某个web应用中的WEB-INF/web.xml配置?
- jbuilder8.0 在XP下的安装问题,请高手帮帮忙!!!!!
- 改一个邮箱系统为论坛系统
- javac命令与package的问题?
- 关于java聊天工具,图形化界面+多线程实现中的问题
- 希望大家给点提示,先谢谢了!
- 传递的到底是什么?怎么会这样
cl = int.class;
System.out.println(cl.getName());
通过查api文档得知
class类里的newInstance()
Throws:
InstantiationException - if this Class represents an abstract class, an interface, an array class, a primitive type, or void; or if the class has no nullary constructor; or if the instantiation fails for some other reason.我补过了异常,却没print a stack trace... 吃了一堑不过第一个还是不明白,为什么会有primitive types的class object?class object不是制造对象用的吗,primitive types又不是对象,怎么会有int.class之类的东西,难道声明一个int型也用到了int.class
还是int.class只用来做RTTI? 实验室要关门啦,回去再看看thinking in java的Detecting Types这章...看看我的猜想对不对