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

前端 未结 5 1494
眼角桃花
眼角桃花 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

    To be used only in its own package

    protected - member - Accessible only within its package and its subclasses

    if someone defines a method as final then it cannot be Cannot be overridden and dynamically looked up.

    Reference here: http://www.javacamp.org/javaI/Modifier.html

提交回复
热议问题