• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tiger New Features: author's take  RSS feed

 
Jeff Langr
author
Ranch Hand
Posts: 799
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings Herb,

Does your book offer your take on the relative values of the new features? Do you discuss, for example, when static import might cause more problems than it solves?

Good luck with the book!

-Jeff-
 
Herb Schildt
Author
Ranch Hand
Posts: 253
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff:

In general, I try to remain neutral on the relative merits of features. That is, I try to even-handedly present the material and let the reader decide.

That said, I do, of course, offer warnings where appropriate. And I do offer such a warning in regards to static import. Here is a quote from my book.

As convenient as static import can be, it is important not to abuse it. Remember, the reason that Java organizes its libraries into packages is to avoid namespace collisions. When you import static members, you are bringing those members into the global namespace. Thus, you are increasing the potential for namespace conflicts, ambiguity, and the inadvertant hiding of other names. If you are using a static member once or twice in the program, its best not to import it. Also, some static names, such as System.out, are so recognizable that you might not want to import them. Static import is designed for those situations in which you are using a static member repeatedly, such as when performing a series of mathematical computations. In essence, you should use, but not abuse, this feature.
 
Jeff Langr
author
Ranch Hand
Posts: 799
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Herb!

A natural use of static import that I found was in writing JUnit tests against a production class--particularly where the test had to refer to a handful of static constants defined on the target class.

-Jeff-
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!