Can I print out the name of the variable?

后端 未结 6 648
独厮守ぢ
独厮守ぢ 2021-01-12 15:26

I have created a no. of constant variables, more than 1000, those constants are unique integer.

public static final FOO  335343
public static final BAR  2342         


        
6条回答
  •  攒了一身酷
    2021-01-12 15:39

    I had a similar problem with a long list of int variables that I had to print the name of each variable and its value (main goal was to create a text file that was going to be imported in an Excel file).

    Unfortunately I'm quite new in Java programming, so the only solution that I found (probably wrong) is to use two different arrays: one String array for the String name and another Int array for the corresponding values.

    For example:

    int varName01, varName02, ....
    String[] listNames = new String {"varName01", "varName02", .....
    int[] listValues = new int {varName01, varName02, .....
    for (int i=0; i

    Probably this is not the correct way to do it, so any opinion from some Java expert would be more than welcome. Thanks!

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题