📜  codegrepper java instanceof - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:36.196000             🧑  作者: Mango

代码示例2
if (vehicle instanceof Car) {
        Car car = (Car) vehicle;
        return car.wheelCount;
     } else if (vehicle instanceof Bike) {
          Bike bike = (Bike) vehicle;
         return bike.numberOfWheels;
     } else {
         throw new IllegalArgumentException("Unrecognized vehicle");
     }