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

2019-08-24 03:08发布

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

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

标签: jython
2条回答
男人必须洒脱
2楼-- · 2019-08-24 03:36

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.

查看更多
Ridiculous、
3楼-- · 2019-08-24 03:54

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'
查看更多
登录 后发表回答