primitive

Why can't I call toString() on a Java primitive?

I want to convert a primitive to a string, and I tried: myInt.toString(); This fails with the error: int cannot be dereferenced Now, I get that primitives are not reference types (ie, not an Object) and so cannot have methods. However, Java 5 introduced autoboxing and unboxing (a la C#... which I never liked in C#, but that's besi...

Is this really widening vs autoboxing?

I saw this in another question in reference to shortcomings of the java spec: There are more shortcomings and this is a subtle topic. Check this out: public class methodOverloading{ public static void hello(Integer x){ System.out.println("Integer");}public static void hello(long x){ System.out.println("long");}public stati...

Generic Type Conversion FROM String

Hi Guys, Here is the problem I am having, 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 pr...

Generic Type Checking

OK, here we go again! Following on from my previous question on Converting to a Generic Type from String, I thought I would ask another Generics-related question! This time, is there a way to enforce/limit the types that are passed to PRIMITIVE's? (bool, int, string, etc) Now, I know you can limit the generic type parameter to a type o...

Why won't .NET deserialize my primitive array from a web service?!

Help! I have an Axis web service that is being consumed by a C# application. Everything works great, except that arrays of long values always come across as [0,0,0,0] - the right length, but the values aren't deserialized. I have tried with other primitives (ints, doubles) and the same thing happens. What do I do? I don't want to ch...

How would one code test and set behavior without a special hardware instruction?

Most of the implementations I find require a hardware instruction to do this. However I strongly doubt this is required (if it is, I can't figure out why...) ...

Is it safe to assume an int will always be 32 bits in C#?

In my C# source code I may have declared integers as: int i = 5; or Int32 i = 5; In the currently prevalent 32bit world they are equivalent. However, as we move into a 64bit world am I correct in saying that the following will become the same? int i = 5; Int64 i = 5; ...

Dynamically find the class that represents a primitive Java type

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...

When should I use primitives instead of wrapping objects?

Actually here is a similar topic with little practical value. As far as I understand, primitives perform better and should be used everywhere except for the cases where Object-related features (e.g. null check) are needed. Right? ...

How do I draw lines using XNA?

I've read a bunch of tutorials involving XNA (and it's various versions) and I still am a little confused on drawing primitives. Everything seems to be really convoluted. Can someone show me, using code, the simplest XNA implementation of drawing one or two lines on to the screen? Perhaps with a brief explanation (including the boiler...

Is primitive assigned a memory address?

I am trying to understand the process of declaration and assignment of a primitive type at the back stage. 1) int i; 2) i = 3; for 1), on the memory stack, it assigns a space for storing an int type value named i for 2), it assigns the value 3 to the space preserved above Is there memory address there? From my impression, memory ad...

Why are there no byte or short literals in Java?

I can create a literal long by appending an L to the value; why can't I create a literal short or byte in some similar way? Why do I need to use an int literal with a cast? And if the answer is "Because there was no short literal in C", then why are there no short literals in C? This doesn't actually affect my life in any meaningful wa...

Simple Variables in Java & C++

I saw this sentence in some matrials: "In Java, simple data types such as int and char operate just as in C." I am wondering that actually they are different in Java & C++? In C++, simple variables like the primitives in Java are assigned a memory address as well, so these primitive types in C++ can have a pointer as well. However pri...

What is going to happen to our primitive types when 128-bit processors come out?

When 64-bit processors came out, it wasn't too big of a deal. Sure, C++ people had to deal with the fact that their 32-bit pointer math doesn't work on 64-bit machines, but that's what you get for not using sizeof (or not using Java!), but in most cases, our languages already had 64-bit primitives, so all the compiler needed to do was ...

Anyone using short and byte primitive types, in real apps?

I have been programming in Java since 2004, mostly enterprise and web applications. But I have never used short or byte, other than a toy program just to know how these types work. Even in a for loop of 100 times, we usually go with int. And I don't remember if I have ever came across any code which made use of byte or short, other than ...

Is it possible to use a primitive type (int) in as a generic type in Java?

Specifically, with a SortedMap<Vector<String>, int> I get "dimensions expected after this (int) token." Help! ...

[Java] int or Integer

Hi, I need to create a data transfer object, which I will use for storing the records retrieved from database. In this data transfer object, I need to declare a numeric field. For that which one is better - int or Integer If I am defining the field as Integer, will there be any performance impact because of 'Integer' type if I am going...

Primitive type 'short' - casting in Java

Hello, 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); real...

Java equivalent of unsigned long long?

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? ...

Converting an array of objects to an array of their primitive types.

If you have an array of java objects which have a primitive type (for example Byte, Integer, Char, etc). Is there a neat way I can convert it into an array of the primitive type? In particular can this be done without having to create a new array and loop through the contents. So for example, given Integer[] array what is the neate...