我宣布枚举为:
enum Sex {MALE,FEMALE};
Run Code Online (Sandbox Code Playgroud)
然后,迭代枚举,如下所示:
for(Sex v : Sex.values()){
System.out.println(" values :"+ v);
}
Run Code Online (Sandbox Code Playgroud)
我检查了Java API但找不到values()方法?我很好奇这个方法来自哪里?
API链接:https: //docs.oracle.com/javase/8/docs/api/java/lang/Enum.html
基于其缓慢的声誉,我总是避免使用Java反射.我在当前项目的设计中达到了一个重点,能够使用它会使我的代码更具可读性和优雅性,所以我决定试一试.
我对这种差异感到惊讶,有时候我注意到运行时间差了近100倍.即使在这个简单的例子中它只是实例化一个空类,它也令人难以置信.
class B {
}
public class Test {
public static long timeDiff(long old) {
return System.currentTimeMillis() - old;
}
public static void main(String args[]) throws Exception {
long numTrials = (long) Math.pow(10, 7);
long millis;
millis = System.currentTimeMillis();
for (int i=0; i<numTrials; i++) {
new B();
}
System.out.println("Normal instaniation took: "
+ timeDiff(millis) + "ms");
millis = System.currentTimeMillis();
Class<B> c = B.class;
for (int i=0; i<numTrials; i++) {
c.newInstance();
}
System.out.println("Reflecting instantiation took:"
+ timeDiff(millis) + "ms");
} …Run Code Online (Sandbox Code Playgroud) 每个数据类对象都有一个组件,用于每个属性,如component1,component2等.我想知道Kotlin中是否有任何方法可以迭代类的每个组件.说我上课了:
class User(age:Int, name:String)
Run Code Online (Sandbox Code Playgroud)
我可以这样做:
for(component in aUserObject){
//do some stuff with age or name
}
Run Code Online (Sandbox Code Playgroud)
?
我正在使用最新版本的IntelliJ IDEA(13.1.4),我正在开发自己的自定义注释.
我目前在我的项目中有两个模块
我在Eclipse工作,但我正在尝试迁移IntelliJ,因为我无法忍受Eclipse.我设法通过让Ant构建生成主项目的.jar文件并且Test类将使用此.jar来使它在Eclipse中有点工作.
但是我不能让它在IntelliJ上工作.
在Settings -> Compiler -> Annotation Processor我有一个新的配置文件中,测试项目在此配置文件中,配置文件如下:

我也尝试过更改Processor Path输出文件夹(其中有类META-INF),但没有运气.该generated文件夹由IDE创建,但它找不到任何处理器.
关于如何在这里进行的任何提示?