permaculture playing cards*
The moose likes Beginning Java and the fly likes Static Imports Error: Need help Ranchers. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Static Imports Error: Need help Ranchers." Watch "Static Imports Error: Need help Ranchers." New topic
Author

Static Imports Error: Need help Ranchers.

Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Hi All,
I'm working on java 5 "Static imports" Concept.
I have written 2 programs ,One is a client java file and other is a java file containing static entities as shown below.



Below is my client program where im trying to use static imports to import static entities from Static Test.



I have defined all the entites in my StaticTest.java file as "Static",but why am i still getting this error.???

Well Im using Eclipse IDE for this purpose.
The Path of my files are as below:
MyProject->src->(default package)->under this default package i have the files "StaticTest.java" and "StaticTestClient.java"

I will be highly obliged if you can help me out

--
Deepak Lal

When The Going Gets Tougher,The Tougher gets Going
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Javav Language Specification section 7.5.
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Deepak ,

Though i hv not tried statciu import , my immediate guess would be that methods should be called with () ,otherwsie treated as identifiers .
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Hi Campbell,
I have given the static import declaration correctly itself,
Could you please look into again



Could you please tell me what is wrong in it?

--
Deepak Lal
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
I might have read the error incorrectly, but I think the Java Language Specification contains the explanation for that error. You usually omit the () after the name of a method in a "static import" declaration.

By the way: please don't write "hv," but "have." Explanation here.
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Hi Balu,
Eclipse automatically resolved into getStaticObject;it should not be getStaticObject();
There should not be an extra ().im not talking about that
im talking about the below statement.



Campbell , please help me out.

--
Deepak lal
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Have you read the link I posted?
Maurice Serier
Greenhorn

Joined: Jan 26, 2009
Posts: 2

I don't think you need to import it because it's in the same package.
lift one of the two to another package and the static import will work.



good luck
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Hi Campbell,
Yes, i have read the link
It says the below for SingleStaticImportDeclaration:


SingleStaticImportDeclaration:
import static TypeName . Identifier;


So my below set of statements is also in accordance with the Java language specification for import statements.



Campbell please help me out.
Can you tell me where i have gone wrong....Please
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Did you find the bit about compiler error when importing from the unnamed package?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
And welcome to the Ranch, Maurice Serier.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Hi Deepak, you are dwelling on the wrong part of the spec. You are trying to import from the default package, which the spec says it is a compile time error to try to import from the unnamed (default) package. So you can not do what you want, you need to move the class you are importing from into a package.


Deepak Lal wrote:Hi Campbell,
Yes, i have read the link
It says the below for SingleStaticImportDeclaration:


SingleStaticImportDeclaration:
import static TypeName . Identifier;


So my below set of statements is also in accordance with the Java language specification for import statements.



Campbell please help me out.
Can you tell me where i have gone wrong....Please


Steve
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Thanks Steve and Campbell for pointing out the mistake,
Oops i made a silly mistake...

Thanks All for correcting me..
Static Imports scared "ME" for a while.

Thanks Ranchers
--
Deepak Lal
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
You're welcome
 
 
subject: Static Imports Error: Need help Ranchers.