Skip to content

Commit

Permalink
Fix to Issue #33 - pushing the verbose ImmutableBy...
Browse files Browse the repository at this point in the history
  • Loading branch information
neomatrix369 committed Dec 27, 2012
1 parent 9aef577 commit ade8682
Showing 1 changed file with 23 additions and 3 deletions.
@@ -1,5 +1,25 @@
package org.mutabilitydetector.benchmarks;

public class ImmutableByHavingOnlyAPrivateConstructorUsingTheBuilderPattern {

}
private final String field;

// usual method of making a class immutable
// - make its constructor private: ref EffectiveJava
private ImmutableByHavingOnlyAPrivateConstructorUsingTheBuilderPattern (String field) {
this.field = field;
}

public String getField() {
return field;
}

// inner Builder class
public static class Builder {
public ImmutableByHavingOnlyAPrivateConstructorUsingTheBuilderPattern build() {
// this new OnlyPrivateConstructors() is fooling mutability detector
// it thinks OnlyPrivateConstructors() is no longer immutable due to the
// ability to call new to create an instance of OnlyPrivateConstructors.
return new ImmutableByHavingOnlyAPrivateConstructorUsingTheBuilderPattern("hi");
}
}
}

0 comments on commit ade8682

Please sign in to comment.