Java: Enum parameter in method

后端 未结 7 1783
小鲜肉
小鲜肉 2020-12-29 03:54

I have a method lets say:

private static String drawCellValue(
    int maxCellLength, String cellValue, String align) { }

and as you can no

7条回答
  •  一整个雨季
    2020-12-29 04:03

    Sure, you could use an enum. Would something like the following work?

    enum Alignment {
        LEFT,
        RIGHT
    }
    

    private static String drawCellValue(int maxCellLength, String cellValue, Alignment alignment) { }

    If you wanted to use a boolean, you could rename the align parameter to something like alignLeft. I agree that this implementation is not as clean, but if you don't anticipate a lot of changes and this is not a public interface, it might be a good choice.

提交回复
热议问题