{
  "id": "java/pattern-matching-invalid-type-test",
  "signature": "error: pattern type 'java.lang.String' is not a subtype of the type of the selector expression 'java.lang.Integer'",
  "signature_zh": "错误：模式类型 'java.lang.String' 不是选择器表达式类型 'java.lang.Integer' 的子类型",
  "regex": "pattern type '.*' is not a subtype of the type of the selector expression '.*'",
  "domain": "java",
  "category": "compilation_error",
  "subcategory": null,
  "root_cause": "In a switch expression or pattern matching statement, the pattern type must be a subtype of the selector expression's type; otherwise, the pattern can never match, leading to a compile-time error.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 switch 表达式或模式匹配语句中，模式类型必须是选择器表达式类型的子类型；否则模式永远无法匹配，导致编译时错误。",
  "versions": [
    {
      "version": "Java 17",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Java 19",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Java 21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Change the selector expression to match the pattern type by casting.",
      "why_fails": "Casting changes the compile-time type but may cause ClassCastException at runtime; the pattern should be written to handle the actual type hierarchy.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Use `instanceof` in an if-else chain instead of switch.",
      "why_fails": "While this avoids the compile error, it doesn't leverage pattern matching's exhaustiveness and conciseness, and may reduce code readability.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "Add a default case with a cast pattern.",
      "why_fails": "The default case does not resolve the type mismatch; the pattern type must be a subtype of the selector type at compile time.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure the pattern type is a subtype of the selector type. For example, if selector is `Number`, use `Integer i` pattern instead of `String s`. Corrected code: `switch (obj) { case Integer i -> ...; case String s -> ...; default -> ...; }`",
      "success_rate": 0.95,
      "how": "Ensure the pattern type is a subtype of the selector type. For example, if selector is `Number`, use `Integer i` pattern instead of `String s`. Corrected code: `switch (obj) { case Integer i -> ...; case String s -> ...; default -> ...; }`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a sealed interface or class to restrict the possible types and ensure the pattern types are subtypes.",
      "success_rate": 0.9,
      "how": "Use a sealed interface or class to restrict the possible types and ensure the pattern types are subtypes.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the selector type is a generic type, use a wildcard or type parameter that includes the pattern type, e.g., `List<? extends Serializable>` to allow both String and Integer patterns.",
      "success_rate": 0.85,
      "how": "If the selector type is a generic type, use a wildcard or type parameter that includes the pattern type, e.g., `List<? extends Serializable>` to allow both String and Integer patterns.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "确保模式类型是选择器类型的子类型。例如，如果选择器是 `Number`，使用 `Integer i` 模式而不是 `String s`。修正后的代码：`switch (obj) { case Integer i -> ...; case String s -> ...; default -> ...; }`",
    "使用密封接口或类来限制可能的类型，确保模式类型是子类型。",
    "如果选择器类型是泛型类型，使用包含模式类型的通配符或类型参数，例如 `List<? extends Serializable>` 以允许 String 和 Integer 模式。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.oracle.com/en/java/javase/17/language/pattern-matching.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2024-01-08",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}