0

I'm somewhat new to the realm of programming where someone has already written what you need, and your job is to bundle it up under a simple class that calls the other person's functions, and the typical uses of import strike me as extremely odd.

As an example, I'm using an open-source spell checking jar called jazzy-core.jar. Why do I type

import com.swabunga.spell.engine.spellDictionaryHashMap;

to use some piece of this jar? I was expecting something more like

import jazzy-core.spellDictionaryHashMap;

or even just

import jazzy-core;

Why are all of those words (com, swabunga, etc) necessary, what do they mean, and why is none of them "jazzy"?

4

1 回答 1

0

因为这import并不意味着您实际上将 jar 包含在您的应用程序中。jar 文件可能具有完全不同的名称,因此在 import 语句中指定 jar 文件的名称是不可行的。相反,import允许您在spellDictionaryHashMap不指定其完全限定名称的情况下引用 。那就是你可以写像

spellDictionaryHashMap map = new spellDictionaryHashMap();

代替

com.swabunga.spell.engine.spellDictionaryHashMap map = new com.swabunga.spell.engine.spellDictionaryHashMap();

Java 中的类和接口组织在包中(与 jar 文件无关),这个特定的类在包中com.swabunga.spell.engine

于 2013-08-04T02:09:10.817 回答