才学java,摘自学习书本上的例子,有两个地方看不懂.
//: net/mindview/atunit/Test.java
// The @Test tag.
package net.mindview.atunit;
import java.lang.annotation.*;@Target(ElementType.METHOD)//这个地方的@是什么意思,在哪个帮助文件里有介绍.
@Retention(RetentionPolicy.RUNTIME)
public @interface Test {} ///:~
1. /**
2. * This program displays a greeting from the authors.
3. * @version 1.20 2004-02-28
4. * @author Cay Horstmann
5. */
6. public class Welcome
7. {
8. public static void main(String[] args)
9. {
10. String[] greeting = new String[3];
11. greeting[0] = "Welcome to Core Java";
12. greeting[1] = "by Cay Horstmann";
13. greeting[2] = "and Gary Cornell";
14.
15. for (String g : greeting)//这种写法有点像C,不知道是不是.
16. System.out.println(g);
17. }
18. }
谢谢解答.

解决方案 »

  1.   

    第15行中for (String g : greeting)怎么我没觉得c有这种写法的,C#就有,但C#就foreach (String g in greeting) 有点不同
    由于没学过java,所以其他地方基本帮不上忙,按我理解@应该是跟文档的生成有关的....
      

  2.   

    恩,没错。在1.5后推出了一些新的功能。这种for的写法就是在1.5添加上去的。
      

  3.   

     for (String g : greeting)//这种写法有点像C,不知道是不是.  System.out.println(g); 
     
    通用for each 循环。