ZeroC Ice "checked casts" in Scala
Posted
by Alexey Romanov
on Stack Overflow
See other posts from Stack Overflow
or by Alexey Romanov
Published on 2010-04-22T16:48:53Z
Indexed on
2010/04/22
16:53 UTC
Read the original article
Hit count: 403
ZeroC Ice for Java translates every Slice interface Simple
into (among other things) a proxy interface SimplePrx
and a proxy SimplePrxHelper
. If I have an ObjectPrx
(the base interface for all proxies), I can check whether it actually has interface Simple
by using a static method on SimplePrxHelper
:
val obj : Ice.ObjectPrx = ...; // Get a proxy from somewhere...
val simple : SimplePrx = SimplePrxHelper.checkedCast(obj);
if (simple != null)
// Object supports the Simple interface...
else
// Object is not of type Simple...
I wanted to write a method castTo
so that I could replace the second line with
val simple = castTo[SimplePrx](obj)
or
val simple = castTo[SimplePrxHelper](obj)
So far as I can see, Scala's type system is not expressive enough to allow me to define castTo
. Is this correct?
© Stack Overflow or respective owner