-> “nullが来た”; case Text t -> doSomethingForText(t); case TodoList td -> doSomethingForTodoList(td); case Image i -> doSomethingForImage(i); default -> "おかしな値が来た"; }; } ϝϞͷछྨ͝ͱʹ ॲཧΛৼΓ͚Δ ৽ 34 ҹ͕ἧ͏Α͏ͳ ϑΥʔϚοτʹ͢Δͱ ಡΈ͍͢
title, Body body ) implements Memo {} record TodoList(Id id, Title title, List<Task> tasks) implements Memo {} record Image(Id id, Title title, ImageUrl url, Body body ) implements Memo {} record Video(Id id, Title title, VideoUrl url ) implements Memo {} } 44
t -> doSomethingForText(t); case TodoList td && 0 < td.tasks().size() -> doSomethingForTodoList(td); case TodoList td -> "ToDoが空っぽ"; case Image i -> doSomethingForImage(i); case Video v -> doSomethingForVideo(v); default -> "おかしな値が来た"; }; ϝϞͷछྨΛ૿͢ 45
Title title, Body body ) implements Memo {} record TodoList(Id id, Title title, List<Task> tasks) implements Memo {} record Image(Id id, Title title, ImageUrl url, Body body) implements Memo {} record Video(Id id, Title title, Video Url url) implements Memo {} } 47
t -> doSomethingForText(t); case TodoList td && 0 < td.tasks().size() -> doSomethingForTodoList(td); case TodoList td -> "ToDoが空っぽ"; case Image i -> doSomethingForImage(i) ; case Video v -> doSomethingForVideo(v); }; ϝϞͷछྨΛ૿͢ 49
case null -> "nullが来た"; case Text(Id id, Title title, Body body) -> doSomethingForText(body); case TodoList(Id id Title title, List<Task> tasks) && 0 < tasks().size() -> doSomethingForTodoList(tasks); case TodoList _ -> "ToDoが空っぽ"; case Image(Id id, Title title, ImageUrl url, Body body) -> doSomethingForImage(url, body); }; } 53