<p>There are situations, where it is practical to have a type-cast return a null value instead of throwing a ClassCastException. C# has the <code>as</code> operator to do this. Is there something equivalent available in Java so you don't have to explicitly check for the ClassCastException?</p>

You can use the
```
instanceof
```
keyword in place of C#'s
```
is
```
, but there is nothing like
```
as
```
.
Example:
```
```
if(myThing instanceof Foo) {
   Foo myFoo = (Foo)myThing; //Never throws ClassCastException
   ...
}
```
```