这是Java包导入的原因吗? [英] Is this how Java package imports are supposed to work?
问题描述
我一直在努力学习我的第一个正则表达式。在编译期间,模式
和匹配
一直无法找到找不到符号
错误。
I've been struggling with my first regex. During the compile, Pattern
and Matcher
kept getting cannot find symbol
errors.
我刚刚将 import java.util。*
改为 import java。 util.regex。*
它就像一个梦想。
I just changed import java.util.*
to import java.util.regex.*
and it works like a dream.
我的印象是 import
ing java.util。*
还带来 java.util。*。*
等不是这样吗?我找不到任何解决这个特定问题的文档....
I was under the impression that import
ing java.util.*
would also bring in java.util.*.*
etc. Is that not the case? I can't find any documentation that addresses this specific question....
推荐答案
是的,这就是包导入的工作原理(并且应该在Java中工作。例如,执行 import javax.swing。*;
将导入 javax.swing中的所有类。*
但不子包及其类。
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。*
将不导入 javax.swing.event
或 javax.swing.event。*
Ergo, javax.swing.*
will not import javax.swing.event
or javax.swing.event.*
阅读关注博客,了解一些友好的新手建议。
Read the following blog for some friendly newbie advice.
这篇关于这是Java包导入的原因吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!