Skip to main content

All Questions

3 votes
1 answer
1k views

How to make Java class invisible outside its module for other non-modular projects?

Recently I've found out that if a package inside a module contains public interfaces or classes they are being exported automatically and hence unintentionally visible outside the module in case when ...
diziaq's user avatar
  • 7,542
0 votes
1 answer
3k views

Not implementing a method from an abstract class (and making it not accessible)

I was trying to create some Java classes with some shared methods among them and with some other methods only available for some of those classes (and each of those methods are supposed to be ...
RCaetano's user avatar
  • 663
0 votes
1 answer
133 views

I am not reducing visibility from interface yet I get the "Cannot reduce visibility" compile error [duplicate]

I am working on a employee management system for training, and I made some interfaces so I can work from there. As I was working on it, one of my methods gave me a compiler error, saying that I could ...
user avatar
1 vote
1 answer
301 views

Increase visibility of interface

I have two packages: 1. com.test.hidden: Contains an protected interface MyListener and a public class FancyClass with a public method for registering MyListener objects: package com.test.hidden; ...
Johannes's user avatar
  • 3,350
-1 votes
1 answer
33 views

Interface visibility restriction, but runs fine

When designing a fluid API, sometimes I want to use Interface return types so that the caller can easily follow the available methods or gets compiler errors if he does not (the Step Builder pattern ...
Boris van Katwijk's user avatar
0 votes
0 answers
354 views

Is it possible to make an interface extendable without it being implementable?

To make what I think is a reasonable analogy, suppose I have a "drink" interface. I can fill it, dump it, and maybe do some other things. I need to know how many people are drinking this drink before ...
WhatsInAName's user avatar
4 votes
3 answers
2k views

How to only allow implementations of an interface in the same package

I have a package P with public interface I public class S1 extends Foo implements I public class S2 extends Bar implements I. Now I want to forbid implementations of I outside of P, but I should be ...
DaveFar's user avatar
  • 7,337
1 vote
5 answers
2k views

How to implement an interface on a protected java class

I was looking to implement an interface on a package-private java class, but I am having some difficulty achieving this. Below is an example. class Foo { String something(String str) { ...
andersra's user avatar
  • 1,135