Programming in D for Java Programmers

From D Wiki
Revision as of 12:41, 15 April 2015 by O3o (talk | contribs) (O3o moved page Coming From/Java to Programming in D for Java Programmers)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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 */
}