java - 类名和导入的类名冲突如何让编译器警告
黄舟
黄舟 2017-04-18 09:14:53
0
2
483

是由这个问题https://segmentfault.com/q/1010000005725685引出的一个问题。

// Calendar.java
import java.text.DateFormatSymbols;
import java.util.*;

public class Calendar {
  public static void main(String[] args) {
    GregorianCalendar d = new GregorianCalendar();
  }
}

javac -Xlint Calendar.java编译时并没有报warning,是否有什么选项让编译器报warning。

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(2)
大家讲道理

There will be no warning, you are overthinking it, because of your Calendar的命名空间(就是package)肯定不是java.util, right?

So, the compiler must identify conflicts based on "namespace + class name", so unless you do it package也写成java.util. Otherwise, I think it would be a bit overwhelming to have the compiler report an error/warning!

Peter_Zhu

I just learned Java this morning, and you guys confused me. I feel like I didn't expect it to be so complicated, I simply wrote the class name and file name wrong. It is normal that no warning is reported in this status. After all, the namespace of this class is different from the namespace of java calendar.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!