Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Incorrect statement on page 552, Chapter 10 (K&B7)  RSS feed

 
C Selberg
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently:
If getInstance() weren't public, we would still have a singleton. However, it wouldn't be as useful because only static methods of the class Show would be able to use the singleton.
Correct:
If getInstance() weren't public, we would still have a singleton. However, it wouldn't be as useful because only static methods of the package would be able to use the singleton.
 
Roel De Nijs
Sheriff
Posts: 11077
173
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi C Selberg,

First of all, a warm welcome to CodeRanch!

C Selberg wrote:Currently:
If getInstance() weren't public, we would still have a singleton. However, it wouldn't be as useful because only static methods of the class Show would be able to use the singleton.

That's indeed an incorrect statement and should be added to the errata overview.

C Selberg wrote:Correct:
If getInstance() weren't public, we would still have a singleton. However, it wouldn't be as useful because only static methods of the package would be able to use the singleton.

But that statement is incorrect as well I think the correct statement should be: If getInstance() weren't public, we would still have a singleton. However, it wouldn't be as useful because only methods of the package would be able to use the singleton.

Because instance methods can access static methods without any problem. So every method (instance or static) in the same package will be able to access the getInstance() method.

Hope it helps!
Kind regards,
Roel
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!