guild icon
Toit
#"as" meaning
Thread channel in help
RobvanLopik
RobvanLopik 05/30/2023 11:14 AM
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?
bitphlipphar
bitphlipphar 05/30/2023 12:09 PM
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 .).(edited)
RobvanLopik
RobvanLopik 05/30/2023 12:44 PM
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 :
RobvanLopik
RobvanLopik 05/30/2023 12:46 PM
return (client_ as RandomServiceClient).roll_die handle_
bitphlipphar
bitphlipphar 05/30/2023 12:51 PM
Oh. Yeah. I completely misread your question :🙂:
bitphlipphar
bitphlipphar 05/30/2023 12:53 PM
as is similar to is, but it casts and generates a runtime error if the given object does not implement the given interface.
bitphlipphar
bitphlipphar 05/30/2023 12:54 PM
So you get a runtime check (unless we can optimize it away).
RobvanLopik
RobvanLopik 05/30/2023 01:04 PM
OK, I hadn't expected this explanation in the topic on operator precedence.
10 messages in total