Is this how Java package imports are supposed to work?(这是 Java 包导入应该如何工作的吗?)
问题描述
我一直在为我的第一个正则表达式而苦苦挣扎.在编译过程中,Pattern
和Matcher
不断出现cannot find symbol
错误.
我刚刚将 import java.util.*
更改为 import java.util.regex.*
,它就像在做梦一样.
我的印象是 import
ing java.util.*
会也引入 java.util.*.*
等.不是这样吗?我找不到任何解决这个特定问题的文档......
是的,这就是包导入在 Java 中的工作方式(并且应该工作).例如,执行 import javax.swing.*;
将导入 javax.swing.*
中的所有 classes 但 不是 子包及其类.
所以,javax.swing.*
将 not 导入 javax.swing.event
或 javax.swing.event.*
阅读以下博客以获得一些友好的新手建议.p>
I've been struggling with my first regex. During the compile, Pattern
and Matcher
kept getting cannot find symbol
errors.
I just changed import java.util.*
to import java.util.regex.*
and it works like a dream.
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....
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.
这篇关于这是 Java 包导入应该如何工作的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:这是 Java 包导入应该如何工作的吗?


基础教程推荐
- 降序排序:Java Map 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01