java – 为什么不能从枚举构造函数调用超级构造函数?

前端之家收集整理的这篇文章主要介绍了java – 为什么不能从枚举构造函数调用超级构造函数?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
public enum A {
     A(1);

     private A(int i){
     }

     private A(){
         super(); // compile - error
             // Cannot invoke super constructor from enum constructor A()
     }

}

这里是枚举的层次结构A从抽象java.lang.Enum扩展java.lang.Object

Class c = Class.forName("/*path*/.A");
System.out.println(c.getSuperclass().getName());
System.out.println(Modifier.toString(c.getSuperclass().getModifiers()).contains("abstract"));
System.out.println(c.getSuperclass().getSuperclass().getName());

解决方法





Error <a href="https://www.jb51.cc/tag/502/" target="_blank" class="keywords">502</a> (Server Error)!!1

502. That’s an error.

The server encountered a temporary error and could not complete your request.

Please try again in 30 seconds. That’s all we know.

原文链接:https://www.f2er.com/java/125387.html

猜你在找的Java相关文章