Preventing Multiple Imports of the Same Class

A class can be imported only once into a specific schema branch from only one package. Consider the following exporting schema and exported packages. (Note that ClassB is exported in two packages.)

ExportSchema

ClassA provides method m1 (exported)
ClassB provides method m2 (exported)

PackageA

PackageB

This is valid from the point of view of the exporting schema as it is reasonable for an exporter to provide several packages or multiple versions of the same package, with common classes in each. It is the responsibility of the package importer to prevent multiple imports of the same class.

Now consider the following invalid importing schema and imported packages. ClassB has been imported twice in two different packages, and a local m3 method has been added twice, once on each imported class.

ImportSchema
PackageA

ClassA provides method m1 (imported).
ClassB provides method m2 (imported) and adds local method m3.
PackageB

ClassB provides method m2 (imported) and adds local method m3.

Method m3 would be ambiguous if multiple imports of ClassB were permitted.

Whenever a class is imported or a class is added to an exported package that has been imported, both the JADE development environment and compiler check that no other imported packages in the schema branch have that class. An exception is raised if there is an existing class with the same name.

It is the responsibility of the importer to prevent multiple imports of the same class. Class usage conflicts are marked as being in error when you import the package. For details, see "Importing a Package", later in this chapter.