How do you get a member of an enum in jython?

允我心安 提交于 2019-12-12 06:00:47

问题


enum day{ mon,tue}
enum getday(){
  return day;
}

I want to print the day, like "mon" or "tue". Is it possible?


回答1:


Just invoke the name method. For example:

>>> from java.lang import *              
>>> s = Thread.currentThread().getState()
>>> s
RUNNABLE
>>> type(s)
<type 'java.lang.Thread$State'>
>>> s.name()
u'RUNNABLE'



回答2:


Unless I'm mistaken, it's using the actual Java enum type, in which case you should be able to access the name attribute.

Something like day.getName() would be how you would typically do this in Java. In Java, it would return either "mon" or "tue" depending on the value of the enum instance being accessed.



来源:https://stackoverflow.com/questions/1894069/how-do-you-get-a-member-of-an-enum-in-jython

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!