我如何通过StringBuilder以最佳方式使用toString方法

问题描述 投票:0回答:1

我该如何改变这种方法以变得更多通过使用来优化StringBuilder并避免每次都用+进行字符串连接。

或者可能有更好的方法

public class Cont {
    double valoareImprumut;
    double rata;
    int zileActive;
    TipCont tipCont; //ENUM

    @Override
    public String toString() {
        return "Cont [valoareImprumut=" + valoareImprumut + ", rata=" + rata + ", zileActive=" +zileActive + ", tipCont=" + tipCont + "]";
    }

java string object tostring
1个回答
0
投票

您可以使用Lombok并避免完全编写toString()方法:)

https://projectlombok.org/features/ToString

© www.soinside.com 2019 - 2024. All rights reserved.