Is there any keyword in Java which is similar to the 'AS' keyword of C# [duplicate]
问题 This question already has answers here : How to emulate C# as-operator in Java (6 answers) Closed 5 years ago . As we know C# provides an AS keyword which automatically performs a check whether the Object is of a type and if it is, it then casts it to the needed type else gives a null. public class User { } .... Object obj = someObj; User user = obj As User; ... Here in the above example, An Object obj can be of type User or some other type. The user will either get an object of type User or