Why are protected members allowed in final classes?
Shouldn’t this be a compile-time error?
Edit: as people have pointed out, you can get same package access by using the default modifier instead. It should behave in exactly the same manner, because protected is just default + sub-classes, and the final modifier explicitly denies subclassing, so I think the answer is more than just to provide same package access.
The
protectedmodifier is necessary on methods that overrideprotectedmethods from a base class, without exposing those members to thepublic.In general, you could introduce a lot of unnecessary rules to outlaw implausible combinations (such as
protected static), but it wouldn’t help much. You can’t outlaw stupidity.