I have doubtless said this before, but the idea that protected visibility implies package visibility is screwed up. I’m in the midle of a refactoring where I’m creating a superclass out of an existing class; at some point in this refactoring, I wanted the compiler to force me to use the new superclass instead of the old class. No problem: I’ll mark the old class’s constructor as protected! But everything compiled unchanged: all its users are in the same package, and surely by marking it as protected I intended to grant access to all those classes, right?

Fortunately, there’s another way to get the behavior I desired: I marked the subclass as abstract. But really, package and protected should be orthogonal concepts. And, while I’m complaining, package should not be the default. And maybe package shouldn’t even exist, though I’m not sure – that is a delicate area of language design.

Post Revisions:

There are no revisions for this post.