What's the use case of a protected method in a final class in Java?

前端 未结 5 1495
眼角桃花
眼角桃花 2021-01-18 02:48

Consider this code from the official OpenJDK source of java.awt.font.TextLayout:

public final class TextLayout {

    /* ... */

    protected v         


        
5条回答
  •  再見小時候
    2021-01-18 03:04

    Protected is (see access levels):

    • For extending classes, regardless of package.
    • All classes in current package can access it.

    In the case of a final class, the method's used by other classes in the same package: it's the same as no access modifier (also called "package-private").

提交回复
热议问题