• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding Static Imports!  RSS feed

 
Ranch Hand
Posts: 89
C++ Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just read about static imports (a confusing topic btw!). I don't quite understand what exactly it's importing.
For example: import static System.out.*;
Does it mean..bring all static things in "out" to view?
And I tried to look up the System class in the java api and "out" is a field in the System class but what is "out"? It's an object right? (I just looked up in the java api.."out" is an object of type OutputStream!)


Thanks in advance for any help!
 
author & internet detective
Marshal
Posts: 37518
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashwin Rao wrote:Does it mean..bring all static things in "out" to view?

It would mean that if it compiled. out is a static variable in the System class. It's actually a PrintStream, which is a specific type of OutputStream.

PrintStream doesn't have any static fields/methods though, so there is nothing to import. You can write:



This allows you to call methods like out.println() without having to type System. Since out is static, it can be used in a static import.
 
Ashwin Rao
Ranch Hand
Posts: 89
C++ Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get it now! Thanks a lot!
And also not to sound too "in-awe" but I saw your name in the OCA/OCP book I recently purchased but I am "in-awe" that an author actually helped me! :p
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37518
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashwin Rao wrote:I get it now! Thanks a lot!
And also not to sound too "in-awe" but I saw your name in the OCA/OCP book I recently purchased but I am "in-awe" that an author actually helped me! :p

Aw. Thanks!

And I'm glad you understand it now. You were really close.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!