"as" meaning
# help
r
The preserved word "as" is used in
import as
and is explained in the docs. I can't seem to find its use in
anObject as aClass
. And it is not the simplest word to search for. Am I missing something?
k
You can use
import net.wifi as mywifi
to make the
wifi.open
available as
mywifi.open
. The default prefix is the last segment of the imported path (unless the path starts with
.
).
r
That is exlained in the docs. But I meant the "as" that seems to do some sort of type casting. I saw you added this in your "services" post :
return (client_ as RandomServiceClient).roll_die handle_
k
Oh. Yeah. I completely misread your question 🙂
as
is similar to
is
, but it casts and generates a runtime error if the given object does not implement the given interface.
So you get a runtime check (unless we can optimize it away).
r
OK, I hadn't expected this explanation in the topic on operator precedence.