Are Java enums considered primitive or reference types?

前端 未结 4 1652
臣服心动
臣服心动 2021-02-01 12:28

If I have an enum object, is it considered a primitive or a reference?

4条回答
  •  不思量自难忘°
    2021-02-01 13:09

    Enums are reference types, in that they can have methods and can be executed from command line as well , if they have main method.

    See following "Planet" example from Sun/Oracle

    http://download.oracle.com/javase/tutorial/java/javaOO/enum.html

提交回复
热议问题