Java - private和package-private枚举构造函数之间的区别 [英] Java - Difference between private and package-private enum constructor

查看:248
本文介绍了Java - private和package-private枚举构造函数之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我经常使用枚举。所以我不知道...

Recently I'm quite oftenly using Enumerations. So I wonder...

私有Enum构造函数和任何可见性修饰符(package-private)之间的枚举构​​造函数有什么区别吗?

Is there any difference between a private Enum constructor and a enum constructor withour any visibility modifier (package-private)?

推荐答案

根据java docs


枚举类型的构造函数必须是包私有或私有访问。

The constructor for an enum type must be package-private or private access.

但是要加入 JLS


如果未指定访问修饰符对于枚举类型的构造函数,构造函数是私有的。

If no access modifier is specified for the constructor of an enum type, the constructor is private.

因此,package-private和private之间没有区别。

So there no difference between the package-private and private .

这篇关于Java - private和package-private枚举构造函数之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆