An alias is a way to introduce new names for types. If the type name is already used in the file, is inappropriate, or is too long, you can introduce a different name and use it instead of the original type name. An alias does not introduce a new type, and it is available only before compile time (when writing code). The compiler replaces a class alias with an actual class, so it does not exist at runtime.
Sometimes, we need to use a few classes with the same name in a single file. For example, the InterstitialAd
type is defined both in the Facebook and Google advertising libraries. Let's suppose that we want to use them both in a single file. This situation is common in projects where we need to implement both ad providers to allow a profit comparison between them. The problem is that using both data types in a single file would mean that we need to access one or both of them with a fully qualified class name (namespace and class name):
import com.facebook.ads.InterstitialAd...