enum

Enum, interfaces and (Java 8) lambdas: code compiles but fails at runtime; is this expected?

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: JDK is Oracle' JDK 1.8u65 but the problem has been seen with "as low as" 1.8u25 as well. Here is the full SSCCE: public final class Foo { private interface X { default void x () { } } private enum E1 implements X { INSTANCE , ; } private enum E2 implements X { INSTANCE , ; } public static void main ( final String ... args ) { Stream . of ( E1 . INSTANCE , E2 . INSTANCE ). forEach ( X :: x ); } } This code compiles; but it fails at runtime: Exception in thread "main" java . lang . BootstrapMethodError : call site initialization

Android: How to put an Enum in a Bundle?

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do you add an Enum object to an Android Bundle? 回答1: Just pass it as int from ordinal(). Restore it from values[]. 回答2: Enums are Serializable so there is no issue. Given the following enum: enum YourEnum { TYPE1, TYPE2 } Bundle: // put bundle.putSerializable("key", YourEnum.TYPE1); // get YourEnum yourenum = (YourEnum) bundle.get("key"); Intent: // put intent.putExtra("key", yourEnum); // get yourEnum = (YourEnum) intent.getSerializableExtra("key"); 回答3: I know this is an old question, but I came with the same problem and I would like

Storing json, jsonb, hstore, xml, enum, ipaddr, etc fails with “column ”x“ is of type json but expression is of type character varying”

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When using PostgreSQL to store data in a field of a string-like validated type, like xml , json , jsonb , xml , ltree , etc, the INSERT or UPDATE fails with an error like: column "the_col" is of type json but expression is of type character varying ... or column "the_col" is of type json but expression is of type text Why? What can I do about it? I'm using JDBC (PgJDBC). This happens via Hibernate, JPA, and all sorts of other abstraction layers. The "standard" advice from the PostgreSQL team is to use a CAST in the SQL. This is not useful

Retrieve enum value based on XmlEnumAttribute name value

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I need a Generic function to retrieve the name or value of an enum based on the XmlEnumAttribute "Name" property of the enum. For example I have the following enum defined: Public Enum Currency CDN = 1 USA= 2 EUR= 3 JPN= 4 End Enum The first Currency enum value is 1; the enum name is "CDN"; and the XMLEnumAttribute Name property value is "00". If I have the enum value, I can retrieve the XmlEnumAttribute "Name" value using the following generic function: Public Function GetXmlAttrNameFromEnumValue(Of T)(ByVal pEnumVal As T) As String Dim

How to define enum in swagger.io?

匿名 (未验证) 提交于 2019-12-03 01:18:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Does anyone was able to define possible 'enum' values in Model tab in swaggger version 2.0 ? Example here: http://petstore.swagger.wordnik.com/#!/pet/addPet has a enum option for 'status' property but that example is using version 1.0 of swagger (according to swagger version defined in JSON object). I've tried to achieve the same in version 2.0 but no luck, not sure of documentation is correct for this. Any hint on this? 回答1: "enum" works just like this: { "in": "query", "name": "sample", "description": "a sample parameter with an enum value

Gettin enum types may not be instantiated Exception

匿名 (未验证) 提交于 2019-12-03 01:18:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am getting RuntimeException Enum types may not be instantiated I don't know why. What I want is to identify a year by an integer value like i have 9 so the year for other Methods is 2006. Code: public class P21Make { enum Catalog { year2005(9),year2006(12),year2007(15),year2008(18), year2009(21),year2010(23),year2011(25),year2012(28), year2013(31),year2014(33),year2015(36),year2016(39), year2017(42),year2018(45),year2019(48),year2020(51); private int id; Catalog(int c){ this.id=c; } } public P21Make() { Catalog c = new Catalog(9); // The

Why can enum implementations not access private fields in the enum class

匿名 (未验证) 提交于 2019-12-03 01:17:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I just answered this question by saying how to solve the compilation problem: How to use fields in java enum by overriding the method? But what I don't understand is why the error is happening in the first place. Here is the example written as an enum: public enum MyEnum { FIRST { @Override public String doIt() { return "1: " + someField; //error } }, SECOND { @Override public String doIt() { return "2: " + super.someField; //no error } }; private String someField; public abstract String doIt(); } Here is the exact same thing as abstract

Java Enum definition

匿名 (未验证) 提交于 2019-12-03 01:14:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I thought I understood Java generics pretty well, but then I came across the following in java.lang.Enum: class Enum > Could someone explain how to interpret this type parameter? Bonus points for providing other examples of where a similar type parameter could be used. 回答1: It means that the type argument for enum has to derive from an enum which itself has the same type argument. How can this happen? By making the type argument the new type itself. So if I've got an enum called StatusCode, it would be equivalent to: public class StatusCode

Mockito: How to match any enum parameter

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have this method declared like this private Long doThings(MyEnum enum, Long otherParam); and this enum public enum MyEnum{ VAL_A, VAL_B, VAL_C } Question: How do I mock doThings() calls? I cannot match any MyEnum . The following doesn't work: Mockito.when(object.doThings(Matchers.any(), Matchers.anyLong())) .thenReturn(123L); 回答1: Matchers.any(Class) will do the trick: Mockito.when(object.doThings(Matchers.any(MyEnum.class), Matchers.anyLong())) .thenReturn(123L); As a side note: consider using Mockito static imports: import static org

Get VB.net Enum Description from Value

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I get Enum description from its value? I can get the description from the name using: Public Shared Function GetEnumDescription(ByVal EnumConstant As [Enum]) As String Dim fi As FieldInfo = EnumConstant.GetType().GetField(EnumConstant.ToString()) Dim attr() As DescriptionAttribute = _ DirectCast(fi.GetCustomAttributes(GetType(DescriptionAttribute), _ False), DescriptionAttribute()) If attr.Length > 0 Then Return attr(0).Description Else Return EnumConstant.ToString() End If End Function But I cant figure out how to pass a variable