Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

static import without package  RSS feed

 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to use static import from a class that are not in the package?

all my java/classes are in one folder, no package.

I can access it with ClassName.staticMember.

but want to remove the ClassName. is it possible

thanks
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that you're explaining something not related to your question
First, you're talking about packages, and then about removing the classname to access static members.

1. you should always put classes into packages. Keep things clean, this will avoid you troubles
2. You cannot remove the class name to access static members.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are in a package - it's called the "default" package.
You cannot use a static import (or any import at all in fact) from the default package. This is exactly one reason why should always use a package declaration - you force all clients of the type to also exist in the default package.
 
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!