casting

Avoid unchecked assignment in a map with multiple value types?

对着背影说爱祢 提交于 2019-12-21 03:24:09
问题 I'm having trouble with a warning in Java 7: Unchecked assignment: 'java.lang.Class' to 'java.lang.Class<T>' I'm getting it on the line Class<T> type = typeMap.get(key); in the get function below. Basically what I'm trying to do here is I want to store a bunch of key/value pairs of unknown types (but all are descendants of Object with the exception of null), but not lose the type. So I created a class with the following content using generics. It has two maps (one to store the data and one to

scala: FOO cannot be cast to FOO

那年仲夏 提交于 2019-12-21 03:00:21
问题 In Scala, I am incredibly confused by this fairly tautological error message: java.lang.ClassCastException: FOO cannot be cast to FOO I would expect that someone can always be cast to its own type. Context I am trying to run the following wrapper around the scala compiler, located at http://code.google.com/p/rooscaloo/source/browse/trunk/rooscaloo/src/org/darevay/rooscaloo/Interpreter.scala Unfortunately, Scala is saying ResultHolder cannot be cast to ResultHolder when I do the following:

Writing unsigned int of 4 bytes over network

半城伤御伤魂 提交于 2019-12-21 02:59:35
问题 I have problem writing an unsigned 4 bytes int in java. Either writing a long value in java has different result on 64 bit MacOS and 32 bit Linux (Ubuntu) OR Writing to network a 4 byte unsigned int has a problem. The following call works perfectly on my local OSX writeUInt32(999999,outputstream) Reading it back gives me 999999 However when the application is deployed to a network writing a long value results in some other random number (I assume the endian has been switched?) and reading it

c++ difference between reinterpret cast and c style cast

放肆的年华 提交于 2019-12-21 02:43:28
问题 Code: char keyStr[50]={ 0x5F, 0x80 /* bla bla */ }; uint32_t* reCast = reinterpret_cast< uint32_t* >( &keyStr[29] ); uint32_t* reCast2 = ( uint32_t* )&keyStr[29]; if( reCast == reCast2 ){ cout << "Same Thing!"; } Output: Same Thing! I wonder what's the difference between the two casting methods. Also if you could specify ( with examples ) difference between static_cast, dynamic_cast, and other types of casting you know ( i.e. while staying as low level and as close to assembly language as

Extracting value of xml tag in PostgreSQL

爱⌒轻易说出口 提交于 2019-12-20 20:26:40
问题 Below is the column response from my Postgres table. I want to extract the status from all the rows in my Postgres database. The status could be of varying sizes like SUCCESS as well so I do not want to use the substring function. Is there a way to do it? <?xml version="1.0" ?><response><status>ERROR_MISSING_DATA</status><responseType>COUNTRY_MISSING</responseType><country_info>USA</country_info><phone_country_code>1234</phone_country_code></response> so my table structure is like this Column

Comparing enum flags in C#

左心房为你撑大大i 提交于 2019-12-20 18:28:04
问题 I need to detect if a flag is set within an enum value, which type is marked with the Flag attribute. Usually it is made like that: (value & flag) == flag But since I need to do this by generic (sometimes at runtime I event have only an "Enum" reference. I can not find an easy way to use the & operator. At the moment I make it like this: public static bool IsSet<T>(this T value, T flags) where T : Enum { Type numberType = Enum.GetUnderlyingType(typeof(T)); if (numberType.Equals(typeof(int)))

Ternary operator behaviour inconsistency [duplicate]

柔情痞子 提交于 2019-12-20 17:33:05
问题 This question already has answers here : Cannot implicitly convert type 'int' to 'short' [duplicate] (9 answers) Closed 5 years ago . Following expression is ok short d = ("obj" == "obj" ) ? 1 : 2; But when you use it like below, syntax error occurs short d = (DateTime.Now == DateTime.Now) ? 1 : 2; Cannot implicitly convert type 'int' to 'short'. An explicit conversion exists (are you missing a cast?) Can anyone explain why this is so? Is there a difference between comparing string-to-string

How do I disable Android @IntDef annotation checks in special cases?

北城余情 提交于 2019-12-20 16:30:07
问题 One such case is reading an int from a Bundle and storing it into the variable restricted by @IndDef annotation: public class MainActivity extends ActionBarActivity { @IntDef({STATE_IDLE, STATE_PLAYING, STATE_RECORDING}) @Retention(RetentionPolicy.SOURCE) public @interface State {} public static final int STATE_IDLE = 0; public static final int STATE_PLAYING = 1; public static final int STATE_RECORDING = 2; @MainActivity.State int fPlayerState = STATE_IDLE; @Override protected void onCreate

How do I disable Android @IntDef annotation checks in special cases?

坚强是说给别人听的谎言 提交于 2019-12-20 16:30:07
问题 One such case is reading an int from a Bundle and storing it into the variable restricted by @IndDef annotation: public class MainActivity extends ActionBarActivity { @IntDef({STATE_IDLE, STATE_PLAYING, STATE_RECORDING}) @Retention(RetentionPolicy.SOURCE) public @interface State {} public static final int STATE_IDLE = 0; public static final int STATE_PLAYING = 1; public static final int STATE_RECORDING = 2; @MainActivity.State int fPlayerState = STATE_IDLE; @Override protected void onCreate

MySQL CAST as DATE

假如想象 提交于 2019-12-20 16:28:11
问题 I'm trying to understand what casting a value to the DATE type in MySQL does. Here are some things I have tried: SELECT CAST('3' AS DATE); -- null SELECT CAST(3 AS DATE); -- null SELECT CAST('2014-07-01 19:00:01' AS DATE); -- 2014-07-01 SELECT DATE('2014-07-01 19:00:01'); -- 2014-07-01 SELECT CAST('2014-07-01' AS DATE); -- 2014-07-01 SELECT DATE('2014-07-01'); -- 2014-07-01 SELECT CAST('2014-07-50' AS DATE); -- null SELECT DATE('2014-07-50'); -- null SELECT DATE(''), CAST('' AS DATE), DATE(0)