找出这段生成方法为何不属于稳定的Java 17源码。 static String label( Object value) {
return switch (value) {
case String text when ! text . isBlank () -> text . strip ();
case String text -> "blank" ;
default -> "other" ;
};
}
查看答案
上一道练习 审查生成的CSV行导入器 审查AI代码
问问你的AI 让你的AI把这段代码改成引导式找错练习。
Claude ChatGPT 复制提示词 I am reading "找出这段生成方法为何不属于稳定的Java 17源码。" on CodeWiki (https://codewiki.com/zh/practice/spotbug/java/java17-features/spotbug-java21-switch-in-java17/).
Context (verbatim from the page):
"""
static String label(Object value) {
return switch (value) {
case String text when !text.isBlank() -> text.strip();
case String text -> "blank";
default -> "other";
};
}
"""
Introduce three subtle bugs into the example above and let me find them. Reveal each answer only after I have guessed.
Answer in 中文. Keep code examples in java. Where you are unsure, say so.