Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

import static??

 
mansi gupte
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import static sun.scjp.com.*;

Is the above statement valid? If so why is the keyword used over here, what is its significance?
 
Campbell Ritchie
Sheriff
Pie
Posts: 50241
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. If you search through this forum you will find it used, and you also find this link to the Sun website. I am not convinced I agree with the bit about "very sparingly."
By the way: is a package beginning with sun. safe for use? I can't remember the details, but there are some packages beginning with com. or sun. which are regarded as experimental.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's only valid if "sun.scjp.com" is a class. With static import you're saying: import all (or those named) static members from a class.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:By the way: is a package beginning with sun. safe for use? I can't remember the details, but there are some packages beginning with com. or sun. which are regarded as experimental.

Not experimental, but packages that start with sun, sunw and com.sun are not part of the public API, and any classes in those packages can change or even disappear from one JRE release to another. Therefore, you should not use them unless you are willing to restrict users of your application to a specific JRE version or a few specific versions.

I have seen one application that works only with Java 1.4.2_08 - even 1.4.2_10 breaks the code. The reason: the developers used a class that isn't part of the public API.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50241
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was the sort of thing I was thinking about, Rob. Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic