<s>
In	O
class-based	B-Application
programming	I-Application
,	O
downcasting	B-Application
or	O
type	O
refinement	O
is	O
the	O
act	O
of	O
casting	O
a	O
reference	O
of	O
a	O
base	O
class	O
to	O
one	O
of	O
its	O
derived	O
classes	O
.	O
</s>
<s>
In	O
many	O
programming	O
languages	O
,	O
it	O
is	O
possible	O
to	O
check	O
through	O
type	B-Application
introspection	I-Application
to	O
determine	O
whether	O
the	O
type	O
of	O
the	O
referenced	O
object	O
is	O
indeed	O
the	O
one	O
being	O
cast	O
to	O
or	O
a	O
derived	O
type	O
of	O
it	O
,	O
and	O
thus	O
issue	O
an	O
error	O
if	O
it	O
is	O
not	O
the	O
case	O
.	O
</s>
<s>
In	O
other	O
words	O
,	O
when	O
a	O
variable	O
of	O
the	O
base	O
class	O
(	O
parent	O
class	O
)	O
has	O
a	O
value	O
of	O
the	O
derived	O
class	O
(	O
child	O
class	O
)	O
,	O
downcasting	B-Application
is	O
possible	O
.	O
</s>
<s>
Some	O
languages	O
,	O
such	O
as	O
OCaml	B-Language
,	O
disallow	O
downcasting	B-Application
.	O
</s>
<s>
Downcasting	B-Application
is	O
useful	O
when	O
the	O
type	O
of	O
the	O
value	O
referenced	O
by	O
the	O
Parent	O
variable	O
is	O
known	O
and	O
often	O
is	O
used	O
when	O
passing	O
a	O
value	O
as	O
a	O
parameter	O
.	O
</s>
<s>
In	O
this	O
approach	O
,	O
downcasting	B-Application
prevents	O
the	O
compiler	O
from	O
detecting	O
a	O
possible	O
error	O
and	O
instead	O
causes	O
a	O
run-time	O
error	O
.	O
</s>
<s>
Downcasting	B-Application
myObject	O
to	O
String	O
( '( 	O
String	O
)	O
myObject	O
 '	O
)	O
was	O
not	O
possible	O
at	O
compile	O
time	O
because	O
there	O
are	O
times	O
that	O
myObject	O
is	O
String	O
type	O
,	O
so	O
only	O
at	O
run	O
time	O
can	O
we	O
figure	O
out	O
whether	O
the	O
parameter	O
passed	O
in	O
is	O
logical	O
.	O
</s>
<s>
While	O
we	O
could	O
also	O
convert	O
myObject	O
to	O
a	O
compile-time	O
String	O
using	O
the	O
universal	O
java.lang.Object.toString( )	O
,	O
this	O
would	O
risk	O
calling	O
the	O
default	O
implementation	O
of	O
toString( )	O
where	O
it	O
was	O
unhelpful	O
or	O
insecure	O
,	O
and	O
exception	O
handling	O
could	O
not	O
prevent	O
this	O
.	O
</s>
<s>
Compile-time	O
downcasting	B-Application
is	O
implemented	O
by	O
static_cast	O
,	O
but	O
this	O
operation	O
performs	O
no	O
type	O
check	O
.	O
</s>
<s>
A	O
popular	O
example	O
of	O
a	O
badly	O
considered	O
design	O
is	O
containers	O
of	O
top	O
types	O
,	O
like	O
the	O
Java	B-Language
containers	O
before	O
Java	B-Language
generics	I-Language
were	O
introduced	O
,	O
which	O
requires	O
downcasting	B-Application
of	O
the	O
contained	O
objects	O
so	O
that	O
they	O
can	O
be	O
used	O
again	O
.	O
</s>
