私はEffective Java bookを試して楽しんでいます。Builder パターンを読んで、それで遊んでみました。私はこのようなコードを持っています(Groovyで):
public class Anto {
public static void main(String[] args) {
def testing = new Java.Builder(1).author("antoaravinth").build()
println testing.author
}
}
class Java {
int version
def author
int release_number
public static class Builder {
int version
def author = ""
int release_number = 0
public Builder(int version) {
this.version = version
}
public Builder version(int version)
{
version = version
return this
}
public Builder author(def author)
{
author = author
return this
}
public Builder release_number(int release_number)
{
release_number = release_number
return this
}
public Java build() {
return new Java(this);
}
private Java(Builder builder)
{
version = builder.version
author = builder.author
release_number = builder.release_number
}
}
}
しかし、次のようなエラーが発生します:
Caught: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: Java(Java$Builder)
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: Java(Java$Builder)
at Java$Builder.build(Anto.groovy:43)
at Java$Builder$build.call(Unknown Source)
at Anto.main(Anto.groovy:4)
なぜこれが起こるのかわかりません!どこで間違ったのですか?