Skip to main content

Questions tagged [package-private]

Package private is the default access-control modifier in Java. If a member of a class is not annotated with `private`, `protected`, or `public`, then the member is `package private` by default. When a member is `package-private`, it can only be accessed by the parent class, and other classes in the same package.

package-private
2 votes
2 answers
99 views

Protected and "package-private" visibility when inheriting from class in different package

I'm kind of new to visibility and want to really internilize these concepts. I've learnt that "package-private", the default visibility in Java, allows us to see fields from classes in the ...
Daniel Hidalgo Chica's user avatar
0 votes
0 answers
83 views

Why package-private classes are not accessible from nested packages?

I was planning a testing strategy for one of the projects I'm working for and my plan was to create some package-private annotations and make them available only down the package structure. For ...
Jaumzera's user avatar
  • 2,349
0 votes
0 answers
98 views

How to make relation between entities from different packages and keep encapsulation?

I have problems with architecture of my project application. I wanted to avoid all classes being public (it is problem of layer packaging), so I created vertical packages as shown below on the screen-...
viep's user avatar
  • 1
3 votes
1 answer
446 views

howt to use mBagOfTags in ViewModel android?

I have object that implement Closeable interface and want to close() method called when my ViewModel is clear. I know to implement onCleared method of ViewModel but I want to use mBagOfTags in ...
Ali Elahi's user avatar
  • 141
5 votes
2 answers
1k views

Javascript: Export things inside the module, internally

In Java, we have 4 visibility levels. Except public and private, we have protected level and a default level (with no modifier) that is also called "package-local" or "package-private&...
Mir-Ismaili's user avatar
7 votes
2 answers
4k views

How can I open class only to test class?

I'm mainly a Java developer and wonder about structure when writing unit test in kotlin, Assuming there's no package-private in kotlin private to restrict visibility to the file internal to restrict ...
Ori Marko's user avatar
  • 58.1k
22 votes
4 answers
2k views

Inheritance at package visibility in Java

I am looking for an explanation for the following behavior: I have 6 classes, {a.A,b.B,c.C,a.D,b.E,c.F}, each having a package visible m() method that writes out the class name. I have an a.Main ...
TFuto's user avatar
  • 1,442
1 vote
0 answers
138 views

javadoc generate "extends Object" instead of the real class when the parent class is package private and comes from another module

My file structure. I have 2 directories next to each other. module1 and module2. module1: src\hu\package1\TestPackagePrivateClass.java: package hu.package1; abstract class TestPackagePrivateClass {...
dfritsi's user avatar
  • 1,222
3 votes
1 answer
2k views

Lombok builder package scope

I would like to generate package-scope builder using Lombok, but I'm not sure if it's possible (I didn't find any clues in documentation). By default Lombok generates public builder, i.e. this code: ...
k13i's user avatar
  • 4,241
44 votes
2 answers
18k views

Why JUnit 5 default access modifier changed to package-private

Why is the default access modifier in JUnit 5 package-private? Tests in JUnit 4 had to be public. What is the benefit of changing it to package-private?
wojtek1902's user avatar
0 votes
1 answer
62 views

Package-private member visibility in complex inheritance / package combinations - Qiuck General Rule to verify visibility

If Base and Derived classes are in different packages then package-private member from Base shall not be inherited and thus it shall be absent in Derived, that is such member shall be inaccessible ...
Code Complete's user avatar
0 votes
0 answers
186 views

Adding an external class with the same package name and breaking encapsulation

I've run into this statement when I was reading a book on Kotlin: With Java, the encapsulation can be easily broken, because external code can define classes in the same packages used by your ...
stdout's user avatar
  • 2,591
2 votes
1 answer
41 views

Are packages (that share a name) combined during compliation?

I'm almost certain this question has been asked, but I'm not sure what to search for regarding it. Anyway, I was was curious if it would be possible to create a class that extends ByteBuffer. I ...
Jacob G.'s user avatar
  • 29.4k
1 vote
2 answers
487 views

How to create mock object of a class which is package private

I have a class. It has a companion object A with a factory method. class A private[somepackage](x: Int) { } object A { def createA(y: Int): A = { new A(y) } } Now I need to create the mock ...
user9920500's user avatar
0 votes
2 answers
453 views

Is it possible to extend a package private class defined in a 3rd party jar in Scala

Is it possible to extend a package private class in scala that is defined in a 3rd party jar. So for instance if a 3rd party jar that my code depends on has some class like so private [somepackage] A ...
Abdul Rahman's user avatar
  • 1,374

15 30 50 per page