Use fully qualified names for System Types in Apex

Whenever you’re dealing with System types, use fully qualified names to avoid accidental or intentional name shadowing.
public void finish(Database.BatchableContext context)
{
if (!complete && !Test.isRunningTest())
{
System.Database.executeBatch(this);//chaing batch execution
}
}
The code above is good and working, but it can easily be broken if someone introduces a new class with the name Test (yes, it’s legit). And you can consider yourself lucky if the code will just start throwing “Method does not exist or incorrect signature: void isRunningTest() from the type Test” But imagine someone accidentally or intentionally implemented System.Test “interface” in the custom class — this could lead to elusive and unpredicted behaviour. All of this could’ve been avoided just by using fully qualified name System.Test.isRunningTest() instead.
PS: those are legit class names in Apex from the top of my head:
- Test
- JSON
- Database