cast

What is the meaning of the Java warning "Type safety: The cast from Object to List is actually checking against the erased type List"? I get it when I try to cast an Object to a type with generic information, such as in the following code:
Object object = getMyList();List<Integer> list = (List<Integer>) object;...

I've been writing C and C++ code for almost twenty years, but there's one aspect of these languages that I've never really understood. I've obviously used regular casts (i.e.
MyClass *m = (MyClass *)ptr;
all over the place, but there seem to be two other types of casts, and I don't know the difference. What's the difference between th...

A question related to Regular cast vs. static_cast vs. dynamic_cast:
What cast syntax style do you prefer in C++?
C-style cast syntax: (int)foo
C++-style cast syntax: static_cast<int>(foo)
constructor syntax: int(foo)
They may not translate to exactly the same instructions (do they?) but their effect should be the same (right?).
If...

Hi,
How can I cast long to HWND (C++ visual studio 8)?
Long lWindowHandler;
HWND oHwnd = (HWND)lWindowHandler;
But I got the following warning:
warning C4312: 'type cast' : conversion from 'LONG' to 'HWND' of greater size
Thanks.
...

In Jesse Liberty's Learning C# book, he says "Objects of one type can be converted into objects of another type. This is called casting."
If you investigate the IL generated from the code below, you can clearly see that the casted assignment isn't doing the same thing as the converted assignment. In the former, you can see the boxing/un...

There are situations, where it is practical to have a type-cast return a null value instead of throwing a ClassCastException. C# has the as operator to do this. Is there something equivalent available in Java so you don't have to explicitly check for the ClassCastException?
...

I've got a byte() array returned as result of directx sound capture, but for other parts of my program I want to treat the results as single(). Is trundling down the array item by item the fastest way of doing it or is there a clever way to do it ?
The code that gets it is
CType(Me._applicationBuffer.Read(Me._nextCaptureOffset, GetTyp...

When accessing an object in a DataTable retrieved from a database, are there any reasons not to cast the object into your desired type, or are there reasons to use convert? I know the rule is cast when we know what data type we're working with, and convert when attempting to change the data type to something it isn't. Presuming we know w...

May be the question will be a little bit noobie, but can anybody advice me some books/sites/articles about how and when it's better to use typecasting in C++ style and when it would be better to prefer C-style? I've read a few books (Shildt, Eckel) and haven't found good material on this theme though I think it's one of the strongest C+...

For example, when I'm dividing two ints and want a float returned, I superstitiously write something like this:
int a = 2, b = 3;
float c = (float)a / (float)b;
If I do not cast a and b to floats, it'll do integer division and return an int.
Similarly, if I want to multiply a signed 8-bit number with an unsigned 8-bit number, I will ...

Hi,
I have a class storing the name of a WS method to call and the type and value of the only parameter that service receives (it will be a collection of parameters but lets keep it simple for the example):
public class MethodCall
{
public string Method { get; set; }
public Type ParType { get; set; }
public string ParValue { get; ...

What is the proper way to cast from an 'OLE_HANDLE' to an 'HICON' for an x64 target build?
In particular with a normal C-Style cast, I get this warning when compiling with an x64 config:
warning C4312: 'type cast' : conversion from 'OLE_HANDLE' to 'HICON' of greater size
Here is the offending code:
imgList.Add((HICON)ohIcon);
The a...

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

I am not familiar with PHP at all and had a quick question.
I have 2 variables @pricePerUnit and @invoicedUnits. Here's the code that is setting these to values:
$InvoicedUnits = ((string) $InvoiceLineItem->InvoicedUnits);
$pricePerUnit = ((string) $InvoiceLineItem->PricePerUnit);
If I output this, I get the correct values. Lets say ...

I've searched through google (maybe I didn't look hard enough) but I could not find how to turn Math.sqrt into an int.
I want to use Math.sqrt for a for loop and I guess I need it as an int but I can't seem to figure out how to cast the result to an int. So how do I do it?
I tried something similar to Java:
(int) Math.sqrt(num);
Bu...

I am trying to copy the value in bar into the integer foo.
This is what I have so far. When I run it I get a different hex value. Any help would be great.
int main()
{
string bar = "0x00EB0C62";
int foo = (int)bar;
cout << hex << foo;
ChangeMemVal("pinball.exe", (void*) foo, "100000", 4);
return 0;
}
So the ou...