导入java.util.Scanner与同一文件中定义的文件冲突 [英] The import java.util.Scanner conflicts with a file defined in the same file

查看:129
本文介绍了导入java.util.Scanner与同一文件中定义的文件冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

package scanner;

import java.util.Scanner;

public class Scanner {
    public static void main(String[] args) {
        Scanner input = new Scanner (System.in);
        String line = input.nextLine();
    }
}

为什么我收到错误消息导入 java.util.Scanner'与同一文件中定义的文件冲突?

Why am I getting an error message saying 'The import java.util.Scanner' conflicts with a file defined in the same file?

推荐答案

您自己的类命名为扫描仪并且您要导入另一个名为 Scanner 的类。这意味着当您创建 Scanner 类型的变量时,编译器不知道您指的是哪个 Scanner 类。

Your own class is named Scanner and you are importing another class named Scanner. This means the compiler does not know which Scanner class you mean when you create a variable of type Scanner.

尝试将您的班级重命名为其他名称。

Try to rename your class to something else.

或者您可以使用 java .util.Scanner 这样就不用重命名你自己的类了:

Alternatively you could use java.util.Scanner this way without renaming your own class:

public static void main(String[] args) {
    java.util.Scanner input = new java.util.Scanner(System.in);
    ...
}

这篇关于导入java.util.Scanner与同一文件中定义的文件冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆