2005/5/9

     
 

instanceof

artefaktur

| References | Casting | Arrays | Import | instanceof | Package | Synchronization | Throwable | finally | Dangerous | Stack | String |

In Java, the instanceof is an operator. In acdk, it can be used in a similiar way.



In Java, you can test if an Object is a given Class:

// Java
void foo(Object object)
{
  if (object instanceof String) {
    // it is now save to cast it
    String astr = (String)object;
  }
}

In acdk, you can do this with the same idiom:

// C++ / acdk
void foo(RObject object)
{
  if (instanceof(object, String)) {
    // it is now save to cast it
    RString astr = (RString)object;
  }
}
Please refer also to

  •  Casting.
  •  References

     < prevConstructs(5 / 12) next >