Community
Participate
Working Groups
I20060315-1200 The IPackageFragment of a default package should always answer false to #hasSubpackages(). See JLS3 7.4.2: "Note that an unnamed package cannot have subpackages, since the syntax of a package declaration always includes a reference to a named top level package." Currently, it returns true if the package fragment root has packages other than the default.
Unfortunately, the spec for IPackageFragment#hasSubpackages() is slightly different. It says that it "returns whether this package fragment's name is a prefix of other package fragments in this package fragment's root". Since the name of the default package fragment is "", it is always a prefix of any other package fragment's name (if any). This cannot be changed without breaking the IPackageFragment's spec.
(In reply to comment #1) > Since the name of the default package fragment is "", it is always a prefix of > any other package fragment's name (if any). I disagree since packages have a separator which is ".". If other packages should be treated as subpackages of "" their names should be something like ".my.own.subpackage" which is not a valid package name.
(In reply to comment #2) > I disagree since packages have a separator which is ".". If other packages > should be treated as subpackages of "" their names should be something like > ".my.own.subpackage" which is not a valid package name. Yes, this is what JLS3 7.4.2 says. However IPackageFragment#hasSubpackages() is not compatible with JLS3 7.4.2 (since it is using the word 'prefix' and an empty string is always a prefix of any string). So if you wish, you can enter a feature request to ask for a new API that corresponds to JLS3 7.4.2.