Reputation: 189
I have two packages. The first one contains an empty interface and a class implementing it in a single file ("IThing" and "Thing"). The second one contains another Interface ("IThingUser") which has a function returning an object of the type "Thing".
When both files are part of the same package everything works fine, but if they are in two separate packages the one in package2 cannot access the class defined in the first package.
Package1 contains the following file :
package project.package1;
public interface IThing {
}
final class Thing implements IThing {
private int thingField;
public int thingFieldGetter(){
return thingField;
}
}
And package2 has :
package project.package2;
import project.package1.IThing;
public interface IThingUser {
public IThing someFunction(); // Works fine
public Thing anotherFunction();
// "Thing" is not recognized when the two files are in separate packages.
}
Why does this happen ? Is there a way to fix this issue while keeping this architecture ?
PS : I know the structure of this does not make much sense but I did not code package1 and I have to use it as-is.
Upvotes: 0
Views: 54
Reputation: 34255
The problem is that project.package1.Thing
is not visible outside the package project.package1
, but public classes must be defined in their own files.
Upvotes: 2
Reputation: 7212
Class Thing
has package-private visibility. You wouldn't be able to access it outside project.package1
package until it will be implemented as
public final class Thing implements IThing
Upvotes: 0