LAPTOP-8KA88UT5_20200903-陈浩
问题
public enum Sun {
/* public static final Sun SINGLETON = new Sun() ; */
SINGLETON ;
private Sun() {
// 注意,这里不要显式书写super(),因为编译器会补充这里的代码
System.out.println( "Sun无参构造执行" );
}
Sun s = Sun.SINGLETON ;
System.out.println( s );
Sun n = Sun.valueOf( "SINGLETON" ); // 根据枚举常量的名称获取枚举常量
System.out.println( n );
测试类中这两个都返回SIGNLEON,但是第一个不是很懂
吐槽
无
近期评论