val as Type,适用于:
val类型是Type;
可以隐式转换为Type;
可以封箱到Type;
如不能转换为Type;则表达式结果为null。
class A
{}
class B: A
{}
example 1.
A a = new A();
B b = a as B; //now, B is null
example 2.
B b = new B();
A a = b;
B c = a as B; //now, b and c are point to same object reference
使用场景:强制转型可能会抛异常,如不希望处理异常,用as则只需要判断是否null。