J
javaguy44
Hi,
I'm just picked up Bloch's Effective Java and had a question about the
reuse of objects when using a static factory method.
Take the following:
class Foo
{
private Foo() {}
public static Foo getInstance() {
return new Foo()
}
}
How is an object of Foo being reused? All I see is that every time
static getInstance is called, it returns a new Foo object. What am I
not seeing? Am I missing something underneath the hood that the JVM
is checking?
One more question - can only immutable class objects be reused?
Thanks,
Javaguy
I'm just picked up Bloch's Effective Java and had a question about the
reuse of objects when using a static factory method.
Take the following:
class Foo
{
private Foo() {}
public static Foo getInstance() {
return new Foo()
}
}
How is an object of Foo being reused? All I see is that every time
static getInstance is called, it returns a new Foo object. What am I
not seeing? Am I missing something underneath the hood that the JVM
is checking?
One more question - can only immutable class objects be reused?
Thanks,
Javaguy