package-private

How can I open class only to test class?

限于喜欢 提交于 2020-01-23 09:26:24
问题 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 visibility to the module How can I open class only to test class ? Must I write test inside kotlin class or open class to all module (internal)? What's the kotlin way to open method for unit test only? EDIT Found similar question/request in kotlin discuss by @bentolor: How am I supposed to do unit

Java - Difference between private and package-private enum constructor [duplicate]

那年仲夏 提交于 2019-12-31 02:42:12
问题 This question already has answers here : Why can a enum have a package-private constructor? (2 answers) Closed 4 years ago . Recently I'm quite oftenly using Enumerations. So I wonder... Is there any difference between a private Enum constructor and a enum constructor withour any visibility modifier (package-private)? 回答1: According to java docs The constructor for an enum type must be package-private or private access. but Accroding to the JLS If no access modifier is specified for the

When would I use package-private in Java? [duplicate]

僤鯓⒐⒋嵵緔 提交于 2019-12-30 06:36:07
问题 This question already has answers here : Pros and cons of package private classes in Java? (8 answers) Closed 6 years ago . I love access control in any language, but I find that in Java I almost never (if ever) use the package-private access modifier (or lack thereof). I realize that inner classes can be private , protected , or package-private , but outer classes can only be package-private or public . Why can an outer class be package-private but not protected ? What is the benefit of

Why doesn't C# have package private?

孤街醉人 提交于 2019-12-19 13:48:14
问题 I'm learning C# and coming from a Java world, I was a little confused to see that C# doesn't have a "package private". Most comments I've seen regarding this amount to "You cannot do it; the language wasn't designed this way". I also saw some workarounds that involve internal and partial along with comments that said these workarounds go against the language's design. Why was C# designed this way? Also, how would I do something like the following: I have a Product class and a ProductInstance

Kotlin: Make an internal function visible for unit tests

自闭症网瘾萝莉.ら 提交于 2019-12-19 12:24:25
问题 In case the tests are in a different module than the production code (which is common), what's the best way to make internal functions visible for tests? In Java, I would have the production code and the test in the same package and make the methods-to-be-tested package-private (plus, add a @VisibleForTest annotation if the only reason for having it package-private rather than private is the test). Unfortunately, Kotlin doesn't have the concept of package-private. 回答1: Classes and methods

Kotlin: Make an internal function visible for unit tests

為{幸葍}努か 提交于 2019-12-19 12:24:07
问题 In case the tests are in a different module than the production code (which is common), what's the best way to make internal functions visible for tests? In Java, I would have the production code and the test in the same package and make the methods-to-be-tested package-private (plus, add a @VisibleForTest annotation if the only reason for having it package-private rather than private is the test). Unfortunately, Kotlin doesn't have the concept of package-private. 回答1: Classes and methods

How to share package private data between two packages in Java?

依然范特西╮ 提交于 2019-12-06 01:38:43
问题 I have 2 Java packages, A & B. Let's say that some classes in package B want to use some classes in package A however, when a developer comes along and develops package C (or, say, application C), he/she will use my package B but I do not want him/her to be able to use the classes in A that B is using. That is to say, I want my classes in package A to be package private so that they are hidden from the application developer. However, I do want my own package B to be able to access those

Java - Difference between private and package-private enum constructor [duplicate]

余生长醉 提交于 2019-12-02 02:14:32
This question already has an answer here: Why can a enum have a package-private constructor? 2 answers Recently I'm quite oftenly using Enumerations. So I wonder... Is there any difference between a private Enum constructor and a enum constructor withour any visibility modifier (package-private)? According to java docs The constructor for an enum type must be package-private or private access. but Accroding to the JLS If no access modifier is specified for the constructor of an enum type, the constructor is private. So there no difference between the package-private and private . The

Why doesn't C# have package private?

南楼画角 提交于 2019-12-01 15:22:43
I'm learning C# and coming from a Java world, I was a little confused to see that C# doesn't have a "package private". Most comments I've seen regarding this amount to "You cannot do it; the language wasn't designed this way". I also saw some workarounds that involve internal and partial along with comments that said these workarounds go against the language's design. Why was C# designed this way? Also, how would I do something like the following: I have a Product class and a ProductInstance class. The only way I want a ProductInstance to be created is via a factory method in the Product class

When would I use package-private in Java? [duplicate]

血红的双手。 提交于 2019-11-30 20:41:35
This question already has an answer here: Pros and cons of package private classes in Java? 8 answers I love access control in any language, but I find that in Java I almost never (if ever) use the package-private access modifier (or lack thereof). I realize that inner classes can be private , protected , or package-private , but outer classes can only be package-private or public . Why can an outer class be package-private but not protected ? What is the benefit of restricting classes/methods/fields to be seen by the entire package, but not subclasses? I use package-private classes and