Duplicate :
|
|
Duplicate :
|
|
Relates :
|
Name: mc57594 Date: 02/13/97 I often find myself writing code that looks like this: void blah (Object x) { if (x instanceof ClassOne) { ClassOne x1 = (ClassOne) x; ...; } else if (x instanceof ClassTwo) { ClassTwo x2 = (ClassTwo) x; ...; } ...; } It'd sure be nice if Java offered a typecase-like statement, especially since it already has it for exceptions! The above could look something like this: void blah (Object x) { typeswitch (x) { case ClassOne x1: { ...; break; } case ClassTwo x2: { ...; break; } ...; } } company - Electric Communities , email - ###@###.### ======================================================================
|