枚举为什么有构造函数,而接口不能有构造函数?

huangapple go评论75阅读模式
英文:

why enum has constructor when interface cant have one?

问题

已知接口不需要构造函数,因为接口的所有数据成员都是public、static和final的。同样,枚举也将其所有常量都声明为public、static和final,那么它为什么需要/有构造函数?

英文:

It is known that Interface doesn't need constructor because all the data members of interface are public,static and final. Similarly enum also has all its constants as public static and final then how come it needs/had a constructor?

答案1

得分: 5

An interface cannot be instantiated, an enum can (and in fact will be, as each of its members is an instance of the enum itself).

英文:

An interface cannot be instantiated, an enum can (and in fact will be, as each of its members is an instance of the enum itself).

huangapple
  • 本文由 发表于 2020年8月12日 20:04:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/63376156.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定