primitive

Is an int a 64-bit integer in 64-bit C#?

十年热恋 提交于 2019-11-26 09:54:30
问题 In my C# source code I may have declared integers as: int i = 5; or Int32 i = 5; In the currently prevalent 32-bit world they are equivalent. However, as we move into a 64-bit world, am I correct in saying that the following will become the same? int i = 5; Int64 i = 5; 回答1: No. The C# specification rigidly defines that int is an alias for System.Int32 with exactly 32 bits. Changing this would be a major breaking change. 回答2: The int keyword in C# is defined as an alias for the System.Int32

How does double to int cast work in Java

自闭症网瘾萝莉.ら 提交于 2019-11-26 09:46:01
问题 I am new to Java, and wondering how does double to int cast work ? I understand that it\'s simple for long to int by taking the low 32 bits, but what about double (64 bits) to int (32 bits) ? those 64 bits from double in binary is in Double-precision floating-point format (Mantissa), so how does it convert to int internally ? 回答1: It's all documented in section 5.1.3 of the JLS. In the first step, the floating-point number is converted either to a long, if T is long, or to an int, if T is

Java Arrays.asList on primitive array type produces unexpected List type [duplicate]

回眸只為那壹抹淺笑 提交于 2019-11-26 08:36:48
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Arrays.asList() not working as it should? Apparently the return type of Arrays.asList(new int[] { 1, 2, 3 }); is List<int[]> . This seems totally broken to me. Does this have something to do with Java not autoboxing arrays of primitive types? 回答1: The problem is that Arrays.asList takes a parameter of T... array . The only applicable T when you pass the int[] is int[] , as arrays of primitives will not be

Java: Why am I required to initialize a primitive local variable?

孤人 提交于 2019-11-26 08:25:41
问题 public class Foo { public static void main(String[] args) { float f; System.out.println(f); } } The print statement causes the following compile-time error, The local variable f may not have been initialized If primitives in Java already have a default value (float = 0.0f), why am I required to define one? Edit: So, this works public class Foo { float f; public static void main(String[] args) { System.out.println(new Foo().f); } } Thanks, everyone! 回答1: Because it's a local variable. This is

Generic type conversion FROM string

无人久伴 提交于 2019-11-26 07:53:22
问题 I have a class that I want to use to store \"properties\" for another class. These properties simply have a name and a value. Ideally, what I would like is to be able to add typed properties, so that the \"value\" returned is always of the type that I want it to be. The type should always be a primitive. This class subclasses an abstract class which basically stores the name and value as string. The idea being that this subclass will add some type-safety to the base class (as well as saving

Dynamically find the class that represents a primitive Java type

旧巷老猫 提交于 2019-11-26 07:29:00
问题 I need to make some reflective method calls in Java. Those calls will include methods that have arguments that are primitive types (int, double, etc.). The way to specify such types when looking up the method reflectively is int.class, double.class, etc. The challenge is that I am accepting input from an outside source that will specify the types dynamically. Therefore, I need to come up with these Class references dynamically as well. Imagine a delimited file a list of method names with

How can you pass multiple primitive parameters to AsyncTask?

风格不统一 提交于 2019-11-26 06:57:08
问题 There are related questions, such as How can I pass in 2 parameters to a AsyncTask class? , but I ran into the difficulty of trying in vain to pass multiple primitives as parameters to an AsyncTask, so I want to share what I discovered. This subtlety is not captured in the existing questions and answers, so I want to help out anyone who runs into the same problem as I did and save them the pain. The question is this: I have multiple primitive parameters (e.g. two longs) that I want to pass to

Java equivalent of unsigned long long?

。_饼干妹妹 提交于 2019-11-26 06:17:31
问题 In C++, I enjoyed having access to a 64 bit unsigned integer, via unsigned long long int , or via uint64_t . Now, in Java longs are 64 bits, I know. However, they are signed. Is there an unsigned long (long) available as a Java primitive? How do I use it? 回答1: I don't believe so. Once you want to go bigger than a signed long, I think BigInteger is the only (out of the box) way to go. 回答2: Starting Java 8, there is support for unsigned long (unsigned 64 bits). The way you can use it is: Long

Converting characters to integers in Java

依然范特西╮ 提交于 2019-11-26 03:35:51
问题 Can someone please explain to me what is going on here: char c = \'+\'; int i = (int)c; System.out.println(\"i: \" + i + \" ch: \" + Character.getNumericValue(c)); This prints i: 43 ch:-1 . Does that mean I have to rely on primitive conversions to convert char to int ? So how can I convert a Character to Integer ? Edit: Yes I know Character.getNumericValue returns -1 if it is not a numeric value and that makes sense to me. The question is: why does doing primitive conversions return 43 ?

Primitive type &#39;short&#39; - casting in Java

删除回忆录丶 提交于 2019-11-26 02:51:59
问题 I have a question about the primitive type short in Java. I am using JDK 1.6. If I have the following: short a = 2; short b = 3; short c = a + b; the compiler does not want to compile - it says that it \"cannot convert from int to short\" and suggests that I make a cast to short , so this: short c = (short) (a + b); really works. But my question is why do I need to cast? The values of a and b are in the range of short - the range of short values is {-32,768, 32767}. I also need to cast when I