首页 > 解决方案 > 类 FIle 在构造函数中没有参数

问题描述

import java.io.*;
import static java.io.File.separator;


public class File {

  public static void main(String[] args) {
    String dirName = "Neis";
    File dir = new File(dirName);


     } 
} // end of class File

错误:

constructor File in class File cannot be applied to given types;
File dir = new File(dirName);
           ^
required no arguments

为什么 File 的构造函数没有参数?在我的不同程序中,它的工作方式类似,但在不同的计算机上。

标签: javafileconstructor

解决方案


你命名了你的班级File。因此,当您使用 时new File,它指的是您自己的类而不是java.io.File. 你可以通过写来解决这个问题:new java.io.File(dirName)而不是......但我建议你只重命名你自己的类。将您自己的类命名为与常见的核心库类相同是非常令人困惑的。


推荐阅读