java - 类 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 的构造函数没有参数?在我的不同程序中,它的工作方式类似,但在不同的计算机上。
解决方案
你命名了你的班级File
。因此,当您使用 时new File
,它指的是您自己的类而不是java.io.File
. 你可以通过写来解决这个问题:new java.io.File(dirName)
而不是......但我建议你只重命名你自己的类。将您自己的类命名为与常见的核心库类相同是非常令人困惑的。
推荐阅读
- c# - SQL 如何替换一个值
- python - 使用 python 和请求,如何进行正确的 POST 调用以及在哪里找到标头?
- android - FirebaseAppDistribution:appDistributionUpload gradle 命令中缺少应用程序 ID
- mysql - 跨列和行计算值的实例
- javascript - 使用 redux 钩子时使用 redux 操作的最佳选择是什么?
- sql - Impala 2.11:AnalysisException:选择列表中不支持子查询
- swift - 在 SwiftUI 中获取当前的经纬度
- c++ - 是否可以禁止一个类被动态转换为?
- git - Git - 将发布分支合并到主分支
- tensorflow - 任何想法如何解决激活函数的问题?