引用类文件中多个枚举之一

huangapple go评论79阅读模式
英文:

Referencing One of Multiple Enums in a Class File

问题

I'm having some issues referencing a specific enum within a class file.

This class file contains multiple enums. It looks like the following:

public class MyEnumContainer {

    static enum MyEnum1 { ... }

    static enum MyEnum2 { ... }

    :
    :
}

Here is my reference to the example above: Multiple Enums in a Single Class

I'm using this in an XML file. The reference is used in the <type> tag in a <setting> tag.

I currently have a reference to the MyEnumContainer. It looks like the following:
<type>MyEnumContainer</type>.

I've tried using <type>MyEnumContainer.MyEnum1</type> and <type>MyEnumContainer$MyEnum1</type> but the reference was not recognized.

Note: the software that processes this XML is fully functional. I only need to know how to properly reference a specific enum within a class file.

英文:

I'm having some issues referencing a specific enum within a class file.

This class file contains multiple enums. It looks like the following:

>
&gt;public class MyEnumContainer {
&gt;
&gt; static enum MyEnum1 { ... }
&gt;
&gt; static enum MyEnum2 { ... }
&gt;
&gt; :
&gt; :
&gt;}
&gt;

Here is my reference to the example above: <a href="https://stackoverflow.com/questions/30282231/how-to-write-multiple-enum-classes-in-a-class">Multiple Enums in a Single Class</a>

I'm using this in an XML file. The reference is used in the &lt;type&gt; tag in a &lt;setting&gt; tag.

I currently have a reference to the MyEnumContainer. It looks like the following:
&lt;type&gt;MyEnumContainer&lt;/type&gt;.

I've tried using &lt;type&gt;MyEnumContainer.MyEnum1&lt;/type&gt; and &lt;type&gt;MyEnumContainer$MyEnum1&lt;/type&gt; but the reference was not recognized.

Note: the software that processes this XML is fully functional. I only need to know how to properly reference a specific enum within a class file.

答案1

得分: 1

你真正的问题在于你的XML解析器如何解释<type>中的值。如果它不知道如何从类中获取枚举,那么你无能为力。另一方面,它可能知道如何获取枚举,但使用一些奥妙的分隔符将类名与枚举名分开。所以:

&lt;type&gt;MyEnumContainer#MyEnum1&lt;/type&gt;
&lt;type&gt;MyEnumContainer*MyEnum1&lt;/type&gt;

或者

&lt;type&gt;MyEnumContainer(MyEnum1)&lt;/type&gt;
&lt;type&gt;MyEnumContainer[MyEnum1]&lt;/type&gt;

或者

&lt;type enum=&quot;MyEnum1&quot;&gt;MyEnumContainer&lt;/type&gt;
&lt;type inner=&quot;MyEnum1&quot;&gt;MyEnumContainer&lt;/type&gt;

或甚至可能是

&lt;type-enum&gt;MyEnumContainer.MyEnum1&lt;/type-enum&gt;

当然也有可能是

&lt;type&gt;com.company.project.tools.MyEnumContainer.MyEnum1&lt;/type&gt;
&lt;type package=&quot;com.company.project.tools&quot;&gt;MyEnumContainer.MyEnum1&lt;/type&gt;

让你的想象力奔放一点吧...

英文:

Your real problem is how your XML parser interprets the value in &lt;type&gt;. If it does not know how to get an enum from within a class, then there is nothing you can do. On the other hand, it may know how to get at the enum, but uses some arcane delimiter to separate the class name from the enum name. So

&lt;type&gt;MyEnumContainer#MyEnum1&lt;/type&gt;
&lt;type&gt;MyEnumContainer*MyEnum1&lt;/type&gt;

or

&lt;type&gt;MyEnumContainer(MyEnum1)&lt;/type&gt;
&lt;type&gt;MyEnumContainer[MyEnum1]&lt;/type&gt;

or

&lt;type enum=&quot;MyEnum1&quot;&gt;MyEnumContainer&lt;/type&gt;
&lt;type inner=&quot;MyEnum1&quot;&gt;MyEnumContainer&lt;/type&gt;

or maybe even

&lt;type-enum&gt;MyEnumContainer.MyEnum1&lt;/type-enum&gt;

Of course it could also be

&lt;type&gt;com.company.project.tools.MyEnumContainer.MyEnum1&lt;/type&gt;
&lt;type package=&quot;com.company.project.tools&quot;&gt;MyEnumContainer.MyEnum1&lt;/type&gt;

let your imagination run wild...

huangapple
  • 本文由 发表于 2020年8月28日 21:21:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/63634606.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定