• Post Reply Bookmark Topic Watch Topic
  • New Topic

static import from class in default package ?  RSS feed

 
John Mulholland
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, wondering if anyone could confirm what I think the following code is suggesting : that static imports are not possible from a class in the default package ?

I compiled Test1.java (that declares and initialises the static final int CONSTANT) and then subsequently compiled Test2.java (that attempts to import static Test1.CONSTANT) :

Test1.Java

Test2.java


An attempt to compile Test2.java gives the error: "static import only from classes and interfaces"

Any help with this would be appreciated.

Thanks, John
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It says in the Java Language Specification that it is a compile time error to import something from the unnamed package.
 
John Mulholland
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ritchie - I appreciate the response
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome Here is the relevant Java™ Language Specification section. You will find the latest (Java8) version says the names must be qualified, and presumably you cannot qualify names in the unnamed package because you cannot write packageName.ClassName.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!