English 中文(简体)
辅助构造变成 j的 set
原标题:refactor constructors into setters in java

由于我接受许多变数,因此,我用“推算参数”的方法做了调整。 但是,现在所有打电话者都有在线信使。

this.somemethod(new MyParam("a", "b","c","d"); 

i 想通过替换建筑商来证明这一点。

MyParam myParam= new MyParam();
myParam.setA("a");........
.
.
this.somemethod(myParam);

是否有办法?

there was a similar bug reported on eclipse https://bugs.eclipse.org/bugs/show_bug.cgi?id=105324

最佳回答

如果我正确理解你的话,你就希望自动从目前的施工者那里获得一个没有参数的施工者,然后向施工者发出呼吁。 我将这样做,将编组电话带入目前的建筑商,确保它们重新使用所有<条码>公开<>,然后管理对建筑商的因线方法。 Ah,但Eclipse却得 won。 因此,你可以写:

public static A newA(int a, int b) {
    A aa = new A();
    aa.setA(a);
    aa.setB(b);
    return aa;
}

(当然,你必须写上空洞的构体,然后用人工替换所有的人)

a = new A(3,2);

iii

a = A.newA(3,2);

then ,可在newA(方法上登出。 我认为,对双方都毫无价值。 但我并不了解更自动化的方法。

问题回答

是否有办法?

是的,具有类似规定的功能,可回归<代码>>>。

public class MyParam {
    private String foo;
    private int bar;
    // ...and so on...

    public MyParam() {
        // Set reasonable defaults here
    }

    public MyParam letFoo(String foo) {
        this.foo = foo;
        return this;
    }

    public MyParam letBar(int bar) {
        this.bar = bar;
        return this;
    }

    // ...and so on...
}

使用:

someFunction(new MyParam()
             .letFoo("foo")
             .letBar(42)
             .letXyz(...)
             // ...and so on...
);

这一点在A时特别有用。 有几个“参数”存在合理的缺省,因此电梯必须使用所有装置,而B) 有许多参数,因此很容易在事情顺序上消失。

页: 1 Xyz 而不是setXyz,因为作为评注中的海点,setXyz 采用 JavaBean命名公约,但 JavaBean的制片商应当拥有回报价值。 (关于更多情况,见





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签