casting

Why does an NSInteger variable have to be cast to long when used as a format argument?

空扰寡人 提交于 2019-12-17 10:12:37
问题 NSInteger myInt = 1804809223; NSLog(@"%i", myInt); <==== The code above produces an error: Values of type "NSInteger" should not be used as format arguments: add an explicit cast to 'long' instead. The correct NSLog message is actually NSLog(@"%lg", (long) myInt); Why do I have to convert the integer value of myInt to long if I want the value to display? 回答1: You get this warning if you compile on OS X (64-bit), because on that platform NSInteger is defined as long and is a 64-bit integer.

Obtain textbox value from Excel in Java

半城伤御伤魂 提交于 2019-12-17 10:04:29
问题 I have an Excel file and I need to read a value from a textbox inside that Excel file. I am using org.apache.poi library and I tried to obtain the value in the following way: List<HSSFObjectData> obj=workbook.getAllEmbeddedObjects(); for (int i = 0; i < obj.size(); i++) { HSSFTextbox t = (HSSFTextbox) obj.get(i); } Unfortunetly I couldn't cast HSSFTextbox to a HSSFObjectData element. Does anyone know how could this be done? 回答1: Maybe you can do like this: try { InputStream input = new

How to manually (bitwise) perform (float)x?

隐身守侯 提交于 2019-12-17 09:54:11
问题 Now, here is the function header of the function I'm supposed to implement: /* * float_from_int - Return bit-level equivalent of expression (float) x * Result is returned as unsigned int, but * it is to be interpreted as the bit-level representation of a * single-precision floating point values. * Legal ops: Any integer/unsigned operations incl. ||, &&. also if, while * Max ops: 30 * Rating: 4 */ unsigned float_from_int(int x) { ... } We aren't allowed to do float operations, or any kind of

Discard millisecond part from timestamp

折月煮酒 提交于 2019-12-17 08:45:45
问题 How can I discard/round the millisecond part, better if the second part is also removed from a timestamp w/o timezone ? 回答1: A cast to timestamp(0) or timestamptz(0) rounds to full seconds: SELECT now()::timestamp(0); Fractions are not stored in table columns of this type. date_trunc() truncates (leaves seconds unchanged) - which is often what you really want: SELECT date_trunc('second', now()::timestamp); 回答2: Discard milliseconds: SELECT DATE_TRUNC('second', CURRENT_TIMESTAMP::timestamp);

std::lexical_cast - is there such a thing?

空扰寡人 提交于 2019-12-17 08:34:26
问题 Does the C++ Standard Library define this function, or do I have to resort to Boost? I searched the web and couldn't find anything except Boost, but I thought I'd better ask here. 回答1: Only partially. C++11 <string> has std::to_string for the built-in types: [n3290: 21.5/7]: string to_string(int val); string to_string(unsigned val); string to_string(long val); string to_string(unsigned long val); string to_string(long long val); string to_string(unsigned long long val); string to_string(float

Casting LinkedHashMap to Complex Object

淺唱寂寞╮ 提交于 2019-12-17 08:30:09
问题 I've got an application that stores some data in DynamoDB using Jackson to marshall my complex object into a JSON. For example the object I'm marshalling might look like this: private String aString; private List<SomeObject> someObjectList; Where SomeObject might look like this: private int anInteger; private SomeOtherObject; and SomeOtherObject might look like this: private long aLong; private float aFloat; This is fine an the object gets marshalled no problem and stored in the DB as a JSON

Casting to generic type in Java doesn't raise ClassCastException?

早过忘川 提交于 2019-12-17 07:48:21
问题 I have come across a strange behavior of Java that seems like a bug. Is it? Casting an Object to a generic type (say, K ) does not throw a ClassCastException even if the object is not an instance of K . Here is an example: import java.util.*; public final class Test { private static<K,V> void addToMap(Map<K,V> map, Object ... vals) { for(int i = 0; i < vals.length; i += 2) map.put((K)vals[i], (V)vals[i+1]); //Never throws ClassCastException! } public static void main(String[] args) { Map

T-sql - determine if value is integer

徘徊边缘 提交于 2019-12-17 07:41:31
问题 I want to determine if a value is integer (like TryParse in .NET). Unfortunatelly ISNUMERIC does not fit me because I want to parse only integers and not every kind of number. Is there such thing as ISINT or something? Here is some code to make things clear. If MY_FIELD is not int, this code would fail: SELECT @MY_VAR = CAST(MY_FIELD AS INT) FROM MY_TABLE WHERE MY_OTHER_FIELD = 'MY_FILTER' Thank you 回答1: Here's a blog post describing the creation of an IsInteger UDF. Basically, it recommends

Cast LINQ result to ObservableCollection

拥有回忆 提交于 2019-12-17 07:13:22
问题 The fact that it is a LINQ result might perhaps not be relevant for the question, but I'm mentioning it anyway - since this is the context which has resulted in this question. I run a LINQ query. The result is an; IEnumerable<MyClass> I want to put the result into an ObservableCollection; ObservableCollection<MyClass> How do I do this cast? (without running through the IEnumerable and copying elements to the ObservableCollection). I notice LINQ has got a few To..() functions, but it doesn't

Casting vs Converting an object toString, when object really is a string

无人久伴 提交于 2019-12-17 06:34:09
问题 This isn't really an issue, however I am curious. When I save a string in lets say an DataRow, it is cast to Object. When I want to use it, I have to cast it ToString. As far as I know there are several ways of doing this, first is string name = (string)DataRowObject["name"]; //valid since I know it's a string and another one is: string name = DataRowObject["name"].ToString(); I am interested in what is the difference between both? Is the first more efficient? (This is just a speculation, in