Author | Topic: Object Conversion Rules!Pls help me! |
Nirmala ranch hand |
posted July 18, 2000 08:22 PM
Hi all, Please explain me with an example. OldType New Type Class Class,Old class must be Super Class or Array, it is given as 'Only Array of object references types may be converted to an array,and then the old element type must be convertible to the new type. Please explain this array Conversion. Thanks in advance.
|
Nirmala ranch hand |
posted July 19, 2000 05:44 AM
Help Please ............. Nirmala
|
Ajith Kallambella bartender |
posted July 19, 2000 06:51 AM
Nirmala, Only Array of object references types may be converted to an array,and then the old element type must be convertible to the new type This means the following
Hope this helps. Ajith [This message has been edited by Ajith Kallambella (edited July 19, 2000).]
|
Nirmala ranch hand |
posted July 19, 2000 11:16 AM
Thank you so much Ajith. It is clear now. Thanks again. Nirmala
|
Deepak M ranch hand |
posted July 19, 2000 05:58 PM
quote: I don't agree with your statement completely. The only forbidden conversion for array is : Which means if SC and TC are primitive types, then it has to be the same types. But if SC and TC are reference types then
|
Nirmala ranch hand |
posted July 19, 2000 07:25 PM
Hi Deepak, Why this following program gives an error,please look at this:
TestConArray a1=new TestConArray();
By the by what is TC/SC?. Thanks
|
Ajith Kallambella bartender |
posted July 19, 2000 07:37 PM
Deepak, You have raised a very valid point. Infact, if you read my statement correctly, the analogy I have given quote: should hint you that I am not talking about identity conversions. Thanks for clarifying though...
[This message has been edited by Ajith Kallambella (edited July 19, 2000).]
|
maha anna bartender |
posted July 19, 2000 07:45 PM
Nirmala, we all know what primitive arrays are. They are arrays of primitives in java. For example int[], char[], long[], short[]... like that. WE also know that we can assign shorter type var to a wider type var. For example int i=10; long l = i; is valid in Java. But this does not mean , we can do the following. The follwing assignment is NOT valid in java. int[] arr1={1,2}; long[] arr2 = {2,3}; arr2 = arr1; //This is NOT ok. But we can assign an int[] var to ANOTHER int[] var and long[] var to another long[] var, short[] var to another short[] var. This is ok in Java. For example the foll. code is legal.
PLease go through and come back if you have anything to ask. In Deepak's post the SC and TC just means 'SourceClassName' and 'TargetClassName' as we have here the names as 'Base' and 'Subclass'. regds
[This message has been edited by maha anna (edited July 19, 2000).]
|
Nirmala ranch hand |
posted July 19, 2000 08:30 PM
Maha Anna, Thanks a lot for explanation and it is really helped me to understand it better. Thank you all. Nirmala
|
| | |