Class... classes是什么意思?

zch198627 2008-05-21 09:33:06
我在阅读Junit4.4的源代码时
/**
* Constructs a TestSuite from the given array of classes.
* @param classes {@link TestCase}s
*/
public TestSuite (Class<?>... classes) {
for (Class<?> each : classes)
addTest(new TestSuite(each.asSubclass(TestCase.class)));
}
Class<?>... classes这样表示是什么意思?依照说明来看时是类的数组,那为何不这样表示:Class<?>[] classes
...全文
6100 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
余乐 2011-04-14
  • 打赏
  • 举报
回复
研究中。。。。
H101_XjuFromYvDong 2010-10-20
  • 打赏
  • 举报
回复
*<?>是泛型,一种特殊数据类型,如 List<String> list,这就声明了一个String的数据集合。
wensheng_zh2007 2008-05-21
  • 打赏
  • 举报
回复
我也是最近从thinking in java中看到这个,应该和数组的性质一样。
bt_lose 2008-05-21
  • 打赏
  • 举报
回复
<..>中间的可以理解为类型参数
集合中中用的比较多
好处在于不用进行类型转化
避免可能发生的转化异常
zenny_chen 2008-05-21
  • 打赏
  • 举报
回复
Java的...好像也是从1.5开始引入的。这个早在C语言里就有,表示不定参数个数(类型也可不同)。
现在在Java中就表示相同类型不定个数的参数。

2楼说String...与String[]作为行参时一样,这个地方其实有些差异。
比如:void hello(String... args){ } 可以这么调用:hello();
而void hello(String[] args)就不行了。只能hello(null);

而Class类是个泛型,这里使用通配符?作为泛型实参表示classes这些对象可以接受任何类型(类类型)。
apples_009 2008-05-21
  • 打赏
  • 举报
回复
学习了.
nicky_tao 2008-05-21
  • 打赏
  • 举报
回复
...的意思表示0——n个。数组应该存储的是基本数据类型,这里是<>,应该是泛型。
(个人理解,有不对的地方请大家指教)
老紫竹 2008-05-21
  • 打赏
  • 举报
回复
有区别吗?
String[] 和 String... 是一样的
phyeas 2008-05-21
  • 打赏
  • 举报
回复 1
我想楼主理解错了。应该是 Class<?> ... classes
Class<?>代表类型,中间的"..."表示无限参数,classes表示该无限参数的名字
调用可以这样写 TestSuite (String.clsss,Integer.class),但是如果写成数组就不能这样写。必须这样写
TestSuite (new Class<?>[]{String.class,Integer.class});
java反编译工具jad 1.5.8g支持 jdk1.5,jdk1.6。说明很多记住一个万能的命令基本就够用了。jad -sjava -r -8 -o **\*.class ---------------This is README file for Jad - the fast Java Decompiler.Jad home page: http://www.kpdus.com/jad.htmlCopyright 2001 Pavel Kouznetsov (jad@kpdus.com).0. Please read the disclaimer on the Jad home page.1. Installation.Unzip jad.zip file into any appropriate directory on your hard drive.This will create two files: - an executable file named 'jad.exe' (Windows *) or 'jad' (*n*x) - this README fileNo other setup is required.2. How to use JadTo decompile a single JAVA class file 'example1.class' type the following: jad example1.classThis command creates file 'example1.jad' in the current directory.If such file already exists Jad asks whether you want to overwrite it or not.Option -o permits overwriting without a confirmation.You can omit .class extension and/or use wildcards in the names ofinput files.Option -s allows to change output file extension: jad -sjava example1.classThis command creates file 'example1.java'. Be careful when usingoptions -o and -sjava together, because Jad can accidentally overwriteyour own source files.Jad uses JAVA class name as an output file name. For example, if classfile 'example1.class' contains JAVA class 'test1' then Jad will createfile 'test1.jad' rather than 'example1.jad'. If you want to specifyyour own output file name use the output redirection: jad -p example1.class > myexm1.javaOption -d allows you to specify another directory for output files,which are created, by default, in the current directory. For example: jad -o -dtest -sjava *.class (or jad -o -d test -s java *.class, which has the same effect)This command decompiles all .class files in the current directory <

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧