Super.java
package x.y.z;
public abstract class Super {
public CustomClass a() {
return new CustomClass();
}
public abstract String getName();
public abstract String getDescription();
}
Sub.java
package x.y.z;
public abstract class Sub extends Super {
public String getDescription() {
return "Is a Sub";
}
}
User.java
package x.y.z;
public class User {
private class UseCase extends Sub {
public String getName() {
return "UseCase";
}
}
public UseCase use() {
return new UseCase();
}
}
In another part of my application, I'm trying to access new User().use().a(), and I think this is causing an error (although this is a compile-time error).
Trying to compile the above errors:
a() in x.y.z.Super is defined in an inaccessible class or interface
What causes this error and how to fix it?
New question
This makes a mistake for me:
User.java
package x.y.z;
public class User {
private class UseCase extends Sub {
public String getName() {
return "UseCase";
}
}
public Super use() {
return new UseCase();
}
}
Changing the type User.use()to Super"fix" the error.
Is this a problematic “fix”, or will it work fine without any hiccups?
source
share