Why can I anonymously subclass an enum but not a final class?

前端 未结 3 1577
说谎
说谎 2021-01-11 15:43

This code:

public class Sandbox {
    public enum E {
        VALUE {
            @Override
            public String toString() {
                return \"I         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-11 16:20

    If you take the following into account, your concern may be lessened:

    A class which has no non-private constructor is effectively final since it is impossible to declare its subclass outside of its body. It is a minor technical detail whether the class defined by an enum is declared final or not: it will in either case be effectively final.

提交回复
热议问题