You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否在JDL中定义包含多空格分隔词的枚举值?

Can JDL Enums Include Values with Spaces (Like "United Kingdom")?

Short answer: Yes, this is absolutely feasible—but you need to enclose the multi-word enum values in double quotes to ensure the JDL parser interprets them correctly.

Correct Syntax Example

Your original code has a small oversight (missing quotes around the spaced values). Here's the proper way to define your Country enum:

enum Country {
  "Vatican City",
  "United Kingdom"
}

What Happens If You Skip the Quotes?

If you write enum Country { Vatican City,United Kingdom } without quotes, the JDL parser will misinterpret spaces as separators between enum entries. This would result in three invalid entries instead of two: Vatican, City, and a malformed United Kingdom (depending on how the parser handles the comma placement). You’ll likely hit syntax errors during code generation or end up with unexpected enum constants in your final code.

Generated Code Behavior

When you generate code from this properly formatted JDL enum (e.g., Java, TypeScript), the tooling will automatically convert the quoted values into valid language-specific enum structures. For example, in Java you’d get:

public enum Country {
    VATICAN_CITY("Vatican City"),
    UNITED_KINGDOM("United Kingdom");

    private final String value;

    Country(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }
}

The enum constant names are converted to valid identifiers (uppercase with underscores replacing spaces), while the original spaced string is preserved as the display value.

Key Takeaway

As long as you wrap multi-word enum values in double quotes, JDL fully supports enum entries with spaces—perfect for country names, city names, or any other phrase containing whitespace.

内容的提问来源于stack exchange,提问作者Dror

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:01:56