3

Is there any java standards that states that a package private class should have a /package/ in the beginning of the class name?

/*package*/ class MyPackagePrivateClass {
 private var1;
 private var2;
}
whitefox
  • 31
  • 2
  • 2
    I've never seen a standard like that. It's unfortunate that Java didn't give us a way to explicitly say that a class (or other declaration) is package-private. Any time I see a code review with that kind of code, I have to ask whether they inadvertently left out `public` or `private`. Usually it's intentional, but there's no way to tell. However, I've never seen a style standard that helps distinguish this (and putting `PackagePrivate` in every name is just ugly). – ajb Feb 17 '16 at 05:18
  • @ElliottFrisch I've seen "package private" used plenty of times, just not in the offcial Java standard. "Default visibility" just isn't descriptive enough. – ajb Feb 17 '16 at 05:19
  • I've seen code like that around 1997, probably wrote some myself, but it's pointless really. – user207421 Feb 17 '16 at 05:20
  • @EJP I don't think it's pointless at all. If you have a number of classes that are working together to perform some function, it often makes a lot of sense to put them in the same Java package, and then make the "helper" classes visible only inside the package, while making the "main" one that has the API that the outside world will use public. – ajb Feb 17 '16 at 05:23
  • 1
    @ajb You have misunderstood completely. What is pointless is the `/*package*/` comment. The subject of the question. What we're talking about. – user207421 Feb 17 '16 at 05:29
  • 1
    "Everybody else" was talking about the right term for this type of access. I don't see any comments about the C-style comment. (Except your later one.) – ajb Feb 17 '16 at 05:33

1 Answers1

1

Official standards, no. Standards set forth by a particular company or project, maybe.

The problem with standards that require certain documentation (JavaDocs aside) is that they'll have to make a linter to enforce it. Otherwise, it's a pretty useless piece of information.

However, there's nothing "official" about that particular comment style. As others have mentioned in the comments the fact the lack of public or private can either be deliberate or accidental may definitely prompt a particular group to enforce such a standard.

Qix - MONICA WAS MISTREATED
  • 14,451
  • 16
  • 82
  • 145