英文:
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:
>
>public class MyEnumContainer {
>
> static enum MyEnum1 { ... }
>
> static enum MyEnum2 { ... }
>
> :
> :
>}
>
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 <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.
答案1
得分: 1
你真正的问题在于你的XML解析器如何解释<type>中的值。如果它不知道如何从类中获取枚举,那么你无能为力。另一方面,它可能知道如何获取枚举,但使用一些奥妙的分隔符将类名与枚举名分开。所以:
<type>MyEnumContainer#MyEnum1</type>
<type>MyEnumContainer*MyEnum1</type>
或者
<type>MyEnumContainer(MyEnum1)</type>
<type>MyEnumContainer[MyEnum1]</type>
或者
<type enum="MyEnum1">MyEnumContainer</type>
<type inner="MyEnum1">MyEnumContainer</type>
或甚至可能是
<type-enum>MyEnumContainer.MyEnum1</type-enum>
当然也有可能是
<type>com.company.project.tools.MyEnumContainer.MyEnum1</type>
<type package="com.company.project.tools">MyEnumContainer.MyEnum1</type>
让你的想象力奔放一点吧...
英文:
Your real problem is how your XML parser interprets the value in <type>. 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
<type>MyEnumContainer#MyEnum1</type>
<type>MyEnumContainer*MyEnum1</type>
or
<type>MyEnumContainer(MyEnum1)</type>
<type>MyEnumContainer[MyEnum1]</type>
or
<type enum="MyEnum1">MyEnumContainer</type>
<type inner="MyEnum1">MyEnumContainer</type>
or maybe even
<type-enum>MyEnumContainer.MyEnum1</type-enum>
Of course it could also be
<type>com.company.project.tools.MyEnumContainer.MyEnum1</type>
<type package="com.company.project.tools">MyEnumContainer.MyEnum1</type>
let your imagination run wild...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论