Programming in D for Java Programmers
Downcasting
The Java way
if (animal instanceof Cat)
{
Cat cat = (Cat) animal;
/* use cat */
}
The D way
if(auto cat = cast(Cat) animal)
{
/* use cat */
}
The Java way
if (animal instanceof Cat)
{
Cat cat = (Cat) animal;
/* use cat */
}
The D way
if(auto cat = cast(Cat) animal)
{
/* use cat */
}