Optionshould only return
Methods with return type
Option should either return
Some if a suitable value exists or
None if not. Returning
null from such methods can have unintended side effects.
asInstanceOf method allows you to explicitly convert an object from one type to another. However, this method should be used with caution. Passing in an invalid type parameter may cause the method to produce unreliable results.
instanceOf method allows you to check if an object belongs to a particular type. However, this method should be used with caution. Passing in an invalid type parameter may cause the method to produce unreliable results, especially if performing a fruitless type test.
Although Scala allows methods with return type
Any, it is suggested that you opt for a different and a better approach. This is because dealing with
Any may require calls to
asInstanceOf[T] and if the type argument
T is erased during compilation, any calls to
isInstanceOf[T] will return unreliable results.