object - Can Java cast anything? -
i've taken year of java course @ school , understanding of casting pretty limited.
the type of casting understand casting int double. makes sense; 1 become 1.0
the type of casting don't quite understand is: casting custom object (say superrectangle
) customer object (eg, myrectangle
). (this assuming myrectangle
subclass of superrectangle
) happens private or public fields associated instance of superrectangle
? how program know legit move? matters could've casted int string, , supposed mean anyway?
strictly speaking, going int
double
isn't casting, conversion. casting reinterpreting same, unchanged bit pattern in memory belonging type. , precisely casting reference types in java boils down to: have object of definite, unchangeable type, , merely look @ if instance of 1 of supertypes.
you not allowed cast integer
string
because latter not former's supertype. ensured @ compile time , double-checked @ runtime well.
Comments
Post a Comment