Java 1.3.1,编译器错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3365473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 01:31:12  来源:igfitidea点击:

Java 1.3.1, compiler errors

java

提问by Crystal

I'm using a new work computer that has an old sdk, Java 1.3.1, on it and wanted to see if I could do some class homework on it. I have this file from our professor and it works on his machine in class, and I am getting compiler errors when I run it. I checked the Java help files onlines and it looks like Collections have been supported prior to 1.3.1 so I am not sure why I am getting these errors. Here is my code:

我正在使用一台新的工作计算机,上面有一个旧的 sdk,Java 1.3.1,我想看看我是否可以做一些课堂作业。我从我们的教授那里得到了这个文件,它在课堂上在他的机器上运行,当我运行它时出现编译器错误。我在网上查看了 Java 帮助文件,看起来在 1.3.1 之前已经支持集合,所以我不确定为什么会出现这些错误。这是我的代码:

import java.io.*; 
import java.util.*; 

public class WriteFile
{ 

    public static void main(String[] args) 
    { 
        if(args.length == 0) {
            args = new String[] { ".." }; 
        }
        List<String> nextDir = new ArrayList<String>();
        nextDir.add(args[0]); 
        try 
        { 

                while(nextDir.size() > 0) 
                { 
                    File pathName = new File(nextDir.get(0)); 
                    String[] fileNames = pathName.list(); 

                    for(int i = 0; i < fileNames.length; i++) 
                    { 
                        File f = new File(pathName.getPath(), fileNames[i]); 
                            if (f.isDirectory()) 
                            { 
                                System.out.println(f.getCanonicalPath()); 
                        nextDir.add(f.getPath()); 
                        } 
                        } 
                nextDir.remove(0); 
                } 
        } 
            catch(IOException e) 
            { 
                e.printStackTrace(); 
            } 
    } 
} 

Errors: '(' or ']' on line 12 which to me doesn't look like an error. Then a lot of cannot resolve symbol for List, String, nextDir on line 12, etc.

错误:第 12 行的 '(' 或 ']' 对我来说这看起来不像是错误。然后很多无法解析第 12 行的 List、String、nextDir 等符号。

I figured it's either something super obvious, or something wrong with my work configuration. Thanks.

我认为这要么是非常明显的,要么是我的工作配置有问题。谢谢。

回答by Java Drinker

Generics is only supported from java 1.5+

泛型仅从 java 1.5+ 支持

Use regular lists like

使用常规列表,如

List nextDir = new ArrayList();

That should work hopefully

这应该很有希望

回答by Drew Wills

I don't believe generics (i.e. List<String>) were supported prior to Java 5.

我不相信List<String>在 Java 5 之前支持泛型(即 )。