Code first.
class A
{
private A(){}
public static A.Builder Builder()
{
/**
* ERROR:
* No enclosing instance of type A is accessible.
* Must qualify the allocation with an enclosing instance of type A
* (e.g. x.new A() where x is an instance of A).
*/
return new A.Builder();
// Error too
//return new Builder();
}
public class Builder
{
private Builder()
{}
}
}
Q: How to instance the builder but do not change the static Builder and nested class name ?
EDIT
If the class is static, how to save the date for every builder ? how to chain the build process ?
public static class Builder
{
private Builder()
{}
public Builder add(int a)
{
return this;// how to chain the build process ?
}
public Builder add(float a);
public List<Double> Build();
}
OK, I should google java builder pattern first.Here is an example.