In order to answer the question one would need to know:
What kind of object is request?
What kind of class is ToHeader?
What is getHeader supposed to do?
What kind of object is classObject?
What is methodMane supposed to do?
How are the two lines interrelated?
Is it correct that a new object called 'classObject' is declared, which gets its value from a method call to another object also called 'classObject'?
If it's just the placing of '(ToHeader)' that confuses you, it means that the getHeader method is (probably) declared to return 'Object', and that -in order to assign it to a variable of type ToHeader- it needs to be cast to ToHeader. This casting will only succeed if the object returned by the method is in fact of type ToHeader. Since that is not checked here, one must assume that getHeader only ever returns objects of type ToHeader. [ January 14, 2006: Message edited by: Ulf Dittmer ]
Ping & DNS - updated with new look and Ping home screen widget
Let's explan it first with primitive values. First you must understand that the hierachy of primitive values is like this...
...meaning with this that you can always assign a byte variable to a short one, a short one to an int one, and so forth.
The contrary is not always true. Why? Well, for example, a byte varible could contain values from -128 up to 127, and an int variable can easily hold that, but an integer variable could contain -2^31 up to (2^31)-1, so a byte variable cannot always contain an int.
As the compiler cannot know what real values of the variables are going to be at runtime, every time you want to store a wider data type into a narrower one, you will have to explicitly say so to the compiler by means of casting...
That way the compiler makes sure that you know what you're doing, because this conversion might cause loosing some data.
It is the same with Objects. Suppose that...
...is a class hierachy.
This means you can assing to a Mammal object reference to a Lion object reference, like this:
Now, you can do this without casting, because all Lions are Mammals, right? But the contrary is not necesarily true. I mean, not all the Mammals are Lions, correct? It could be a Fox, or any other kind of Mammal.
So, when you want to do downcasting, that means assing an object reference from the parent class to an object reference of the child class you have to explicitly say so by means of the casting operator, like this: