Few things about this one:
* NullPointerException can be thrown here, because as is nullable
* what if as actually is null?
* there is no default case here, probably IllegalArgumentException should be thrown
* extract this into a method and provide a test for it.