You should review the basic of OOP principle of inheritance.
For example I have 3 classes A, B and C; B extends A, C extends A. In this situation i can cast an instance of B to type A, cast an instance of C to type A, but I can't cast an instance of B to type C, vice versa.
First of all thanx for your reply...However in the example which you gave B and C are no where related but they are individually inheriting from class A...and which is the not the case which I have explained if you read it properly.
What I wanted to have is when I can typecast an int to Object class why I cannot have a type conversion from int to my custom class GenericObject which is also extending an Object class(It is just extending the class and doing nothing more than that)
No matter if you override some functions inside GenericObject or not, whenever you extends the Object class, the new class will be considered as successor of Object, not the same (even they do defenitely the same thing). You can try my example with 3 classes A,B,C inherits each other (leave B blank like your GenericObject) and do the typecasting (with A means Object, B means GenericObject and C means int).
var b:A = new B();
var c:A = b as C; <== Same Error right?
You can't do that, you can only pass objects that have GenericObject in their heirarchy. Both int and GenericObject extend Object ( I don't think you need the "extends Object" in the declaration) so any function that has ":Object" or ":*" in its paramter list will be able to take both. However, when you specifiy GenericObject only classes that have GenericObject ( Foo extends GenericObject ) in their heirarchy will be accepted without throwing an error. The int object DOES NOT extend GenericObject or extend any class that does, so it is impossible for it to be accepted as a valid parameter in any function that requires GenericObject
Consider the following function.
public function feed( value:Animal ):*
This function can accept a parameter that is a duck or a human baby. Why, because ducks and humans both have the Animal class in their heirarchy.
Now consider this function
public function putInOvenAt300FWithSeasonSalt( value:EdibleMammal ):
This function will still work for the duck ( even though ducks aren't mammals but whatever, they are for this example ). Now if you try to pass a human baby to this function you will have some problems, well why ? Because even though ducks and human babies both have the Animal class in their heriarchy, they don't both extend the EdibleMammal class. Flex responds by throwing up nasty error messages because you tried to cook a baby.
Thanks for the thorough response...However I do understand the Class Inheritance hierarchy...But I just want to do something how int is getting converting to implicit Object like the same way is there any possibility to do that.
Actually let me explain what am I doing in background what made me to post this..
We are using Flex PMD tool in order to make sure we are writing an efficient and quality code...Hope you are aware of Flex PMD. So when I try to run my application with this tool it shows some errors related to using the dynamic Object class...as shown below:
Do not use Object class. It is a bad practice to use the dynamic class Object. Prefer using strongly typed object, or marker interface in order to avoid silent compilation errors while refactoring
So in order to avoid this error I have created a new GenericObject class which extends the Object class as posted earliar..however it does removes the Flex PMD errors when I try to replace the usage of builtin Object class with my GenericObject class but it is only applicable for all the cases when the receiveing type is the Object indeed but not int or string to the function whose datatype is GenericObject...however it works fine if it is normal object instead of my GenericObject....As explained with an example in my previous post.
How can I avoid such kind of a Flex PMD error is there any alternative approach to do that...DO you have any ideas..??
If you don't add anything meaningful in your GenericObject class and the only purpose of it is to eliminate code-inspection errors of Flex PMD, then you don't need this class and creating redundant classes sounds to me like a bad practice as well.
Check the possibility of changing the Flex PMD rules.
That way you should be able to make that error a warning or just remove it.
Anyway, you can't change the class heirarchy of core types and it sounds a bit like you don't know which variables are being passed around (if a method needs an int variable, provide an int variable, why passing an Object in the first place?).