Is this how Java package imports are supposed to work?

前端 未结 4 435
醉酒成梦
醉酒成梦 2020-12-21 08:34

I\'ve been struggling with my first regex. During the compile, Pattern and Matcher kept getting cannot find symbol errors.

I j

相关标签:
4条回答
  • 2020-12-21 09:19

    Yes, that is how package imports work (and are supposed to work) in Java. For example, doing import javax.swing.*; will import all classes within javax.swing.* but not sub-packages and their classes.

    Ergo, javax.swing.* will not import javax.swing.event or javax.swing.event.*

    Read the following blog for some friendly newbie advice.

    0 讨论(0)
  • 2020-12-21 09:21

    Importing java.util.* will not import java.util.*.*.

    0 讨论(0)
  • 2020-12-21 09:36

    See a link and a quoted excerpt from the link below.

    http://docs.oracle.com/javase/tutorial/java/package/usepkgs.html

    Importing java.awt.* imports all of the types in the java.awt package, but it does not import java.awt.color, java.awt.font, or any other java.awt.xxxx packages. If you plan to use the classes and other types in java.awt.color as well as those in java.awt, you must import both packages with all their files:

    import java.awt.*;
    import java.awt.color.*;
    
    0 讨论(0)
  • 2020-12-21 09:38

    No, package imports only get the direct classes in that package (java.* will not import everything, only ones such as Java.SomeClass, not java.util.SomeClass)

    0 讨论(0)
提交回复
热议问题