<i id='FCGfc'><tr id='FCGfc'><dt id='FCGfc'><q id='FCGfc'><span id='FCGfc'><b id='FCGfc'><form id='FCGfc'><ins id='FCGfc'></ins><ul id='FCGfc'></ul><sub id='FCGfc'></sub></form><legend id='FCGfc'></legend><bdo id='FCGfc'><pre id='FCGfc'><center id='FCGfc'></center></pre></bdo></b><th id='FCGfc'></th></span></q></dt></tr></i><div id='FCGfc'><tfoot id='FCGfc'></tfoot><dl id='FCGfc'><fieldset id='FCGfc'></fieldset></dl></div>
      • <bdo id='FCGfc'></bdo><ul id='FCGfc'></ul>

      <legend id='FCGfc'><style id='FCGfc'><dir id='FCGfc'><q id='FCGfc'></q></dir></style></legend>
      <tfoot id='FCGfc'></tfoot>

      <small id='FCGfc'></small><noframes id='FCGfc'>

      Eclipse/Java - 导入 java.(namespace).* 有害吗?

      Eclipse/Java - is it harmful to import java.(namespace).*?(Eclipse/Java - 导入 java.(namespace).* 有害吗?)
      <legend id='odSoX'><style id='odSoX'><dir id='odSoX'><q id='odSoX'></q></dir></style></legend>
      • <bdo id='odSoX'></bdo><ul id='odSoX'></ul>

        1. <tfoot id='odSoX'></tfoot>

          <small id='odSoX'></small><noframes id='odSoX'>

          • <i id='odSoX'><tr id='odSoX'><dt id='odSoX'><q id='odSoX'><span id='odSoX'><b id='odSoX'><form id='odSoX'><ins id='odSoX'></ins><ul id='odSoX'></ul><sub id='odSoX'></sub></form><legend id='odSoX'></legend><bdo id='odSoX'><pre id='odSoX'><center id='odSoX'></center></pre></bdo></b><th id='odSoX'></th></span></q></dt></tr></i><div id='odSoX'><tfoot id='odSoX'></tfoot><dl id='odSoX'><fieldset id='odSoX'></fieldset></dl></div>
                  <tbody id='odSoX'></tbody>
                本文介绍了Eclipse/Java - 导入 java.(namespace).* 有害吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                为什么 Eclipse 在导入类型时采用细粒度的方法?在 C# 中,我习惯于使用 System.Windows.Controls"并完成它,但 Eclipse 更喜欢单独导入我引用的每个小部件(使用 Ctrl+Shift+O 快捷方式).如果我知道我需要多个类型,那么导入整个命名空间有什么害处吗?

                Why does Eclipse take a fine grained approach when importing types? In C# I'm used to things like "using System.Windows.Controls" and being done with it, but Eclipse prefers to import each widget I reference individually (using the Ctrl+Shift+O shortcut). Is there any harm to importing an entire namespace if I know I'll need multiple types in it?

                推荐答案

                通配符包导入可能造成的唯一危害是,如果多个包中存在多个同名类,则会增加命名空间冲突的机会.

                The only harm that wildcard package imports can cause is an increased chance of namespace collisions if there are multiple classes of the same name in multiple packages.

                例如,我想在 AWT 应用程序中使用 Java Collections Framework 的 ArrayList 类进行编程,该应用程序使用 List GUI 组件来显示信息.举个例子,假设我们有以下内容:

                Say for example, I want to program to use the ArrayList class of the Java Collections Framework in an AWT application that uses a List GUI component to display information. For the sake of an example, let's suppose we have the following:

                // 'ArrayList' from java.util
                ArrayList<String> strings = new ArrayList<String>();
                
                // ...
                
                // 'List' from java.awt
                List listComponent = new List()
                

                现在,为了使用上述内容,必须至少导入这两个类:

                Now, in order to use the above, there would have to be an import for those two classes, minimally:

                import java.awt.List;
                import java.util.ArrayList;
                

                现在,如果我们在包 import 中使用通配符,我们会得到以下内容.

                Now, if we were to use a wildcard in the package import, we'd have the following.

                import java.awt.*;
                import java.util.*;
                

                但是,现在我们有一个问题!

                However, now we will have a problem!

                有一个 java.awt.List 类和一个 java.util.List,所以引用 List 类会很模糊.如果我们想消除歧义,就必须使用完全限定的类名来引用 List:

                There is a java.awt.List class and a java.util.List, so referring to the List class would be ambiguous. One would have to refer to the List with a fully-qualified class name if we want to remove the ambiguity:

                import java.awt.*;
                import java.util.*;
                
                ArrayList<String> strings = new ArrayList<String>();
                
                // ...
                
                // 'List' from java.awt -- need to use a fully-qualified class name.
                java.awt.List listComponent = new java.awt.List()
                

                因此,在某些情况下,使用通配符包 import 可能会导致问题.

                Therefore, there are cases where using a wildcard package import can lead to problems.

                这篇关于Eclipse/Java - 导入 java.(namespace).* 有害吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
                Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
                How to convert Integer to int?(如何将整数转换为整数?)
                How do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
                Inconsistent behavior on java#39;s ==(java的行为不一致==)
                Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)

                <small id='gbkGv'></small><noframes id='gbkGv'>

                    <tbody id='gbkGv'></tbody>
                    <tfoot id='gbkGv'></tfoot>

                      • <bdo id='gbkGv'></bdo><ul id='gbkGv'></ul>

                        <i id='gbkGv'><tr id='gbkGv'><dt id='gbkGv'><q id='gbkGv'><span id='gbkGv'><b id='gbkGv'><form id='gbkGv'><ins id='gbkGv'></ins><ul id='gbkGv'></ul><sub id='gbkGv'></sub></form><legend id='gbkGv'></legend><bdo id='gbkGv'><pre id='gbkGv'><center id='gbkGv'></center></pre></bdo></b><th id='gbkGv'></th></span></q></dt></tr></i><div id='gbkGv'><tfoot id='gbkGv'></tfoot><dl id='gbkGv'><fieldset id='gbkGv'></fieldset></dl></div>
                        <legend id='gbkGv'><style id='gbkGv'><dir id='gbkGv'><q id='gbkGv'></q></dir></style></legend>