Java 1.5 Tiger A Developers Notebook [Electronic resources]

David Flanagan, Brett McLaughlin

نسخه متنی -صفحه : 131/ 82
نمايش فراداده

Chapter 8. Static Imports

Importing Static Members

Using Wildcards in Static Imports

Importing Enumerated Type Values

Importing Multiple Members with the Same Name

Shadowing Static Imports

All right, let's begin with a fair warningthis isn't a very sexy chapter. It's not as exciting as generics, it's not as (obviously) missing a feature in the language as varargs, it's not even as cool as the for/in loop. Instead, this chapter is about a feature that is completely convenience-based. It adds no new functionality to the language, and it doesn't even have much to do with how you write code. Sort of an inauspicious beginning, huh?

Still, that said, static imports are extremely cool, especially when you start to pile on additional language features, such as enumerated types. In a nutshell, static imports allow you to import static classes, variables, and enums, and reference them easily in your code. While you may not get any new functionality, the convenience here is very, very nice. As I've said before, I don't know any good programmer who just loves typing out really long variable names, ten or fifteen times in their programs. Static imports help with just that task, and, as such, are very much worth covering.