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

前端 未结 5 1523
眼角桃花
眼角桃花 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 02:58

    protected members can still be accessed by code from the same package. My guess is that the class used to be non-final in some earlier (perhaps not even public) version, was then made final, and the protected method kept as such because there might be code in the same package that uses it (and not changed to package private simply because nobody saw a benefit from doing so).

提交回复
热议问题