public static void main(String[] args) {
doWork(new DesigningTask());
doWorkClassCast(new DesigningTask());
}
public static void doWorkClassCast(Task task) {
CodingTask codingTask = (CodingTask) task;
System.out.println("doWorkClassCast");
System.out.println(codingTask != null ? "writing code" : "does`t know how to do it");
}
public static void doWork(Task task) {
System.out.println("doWork");
System.out.println(((CodingTask) task) != null ? "writing code" : "does`t know how to do it");
}
static class Task {
}
static class CodingTask extends Task {
}
static class DesigningTask extends Task {
}
просто тут выкидывается class cast
System.out.println(((CodingTask) task) != null ? "writing code" : "does`t know how to do it");
Я не о твоём примере, я о дискуссии в целом
Обсуждают сегодня