0

我真的不知道如何表达这个问题,因为我真的不明白该怎么做

我有两个“.java”文件

创建文件:

public void addRecords(String Package, String ClassName, String[] ListOfBoxes)
{
    format.format("%s", "package " + Package + ";"\n");
    format.format("%s", "@SideOnly(Side.CLIENT)\n");
    format.format("%s", "public class " + ClassName + " extends ModelBiped\n");
    format.format("%s", "{\n");
    format.format("%s", "    ModelRenderer " + ListOfBoxes + ";\n");
    format.format("%s", "}\n");

   }

我试图运行的代码

            createFile file = new createFile();
    file.openFile();
    String[] Boxes = {"test1", "test2", "test3"};
    file.addRecords("default", "ModelTest", Boxes);         
    file.closeFile();

这是输出:

package net.minecraft.client.model;
@SideOnly(Side.CLIENT)
public class ModelTest extends ModelBiped
{
    ModelRenderer [Ljava.lang.String;@3794d372;
}

这就是我要的

package net.minecraft.client.model;
@SideOnly(Side.CLIENT)
public class ModelTest extends ModelBiped
{
    ModelRenderer test1;
    ModelRenderer test2;
    ModelRenderer test3;
}

这可能很简单,但我是 java 的菜鸟

提前致谢

4

2 回答 2

1

You want the Arrays.deepToString method. Rewrite the corresponding line in your addRecords method like this:

format.format("%s", "    ModelRenderer " + Arrays.deepToString(ListOfBoxes) + ";\n");
于 2013-04-13T11:38:57.797 回答
0

try this for createFile:

public void addRecords(String Package, String ClassName, String[] ListOfBoxes)
{
    format.format("%s", "package " + Package + ";"\n");
    format.format("%s", "@SideOnly(Side.CLIENT)\n");
    format.format("%s", "public class " + ClassName + " extends ModelBiped\n");
    format.format("%s", "{\n");
    for (String box : listOfBoxes)
    {
        format.format("%s", "    ModelRenderer " + box + ";\n");
    }
    format.format("%s", "}\n");

}

The difference is that this code renders each element in the array, while your code renders the entire array in one go.

于 2013-04-13T11:39:16.620 回答