aspose file tools*
The moose likes Java in General and the fly likes Static Import in Java 5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Static Import in Java 5" Watch "Static Import in Java 5" New topic
Author

Static Import in Java 5

Harish Tam
Ranch Hand

Joined: Feb 17, 2005
Posts: 71

I am trying to use static import with my code,
the problem is that i cannot use static import for my created custom class but with Java package static import works as designed so just a Question does static import works only with Java packages or is it customizable with custom java files used in project.
If yes then is there any coding structure i am missing while creating my custom java files so as to include them as static import.

Thanks

SCJP 1.4, SCWCD 1.4
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

Can you show us the fields / methods you're trying to import, and the actual import statement that's not working? Because static import should work for all classes.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Harish Tam wrote:....does static import works only with Java packages or is it customizable with custom java files used in project.

Hi. what you mean by Java Package & custom java files here.. Does it mean Java classes already present in JDK & Java classes written by you respectively?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14268
    
  21

What does your code look like? Do you get error messages when you try to compile it? Please copy & paste the exact error messages. The more detailed information you give us, the better we can help you. Right now you've told us too little to answer your question.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Shinil Mohan
Ranch Hand

Joined: Aug 24, 2011
Posts: 37

Can you check if you have used 'static' in the import, I was also having issue, the thing is i forgot to add 'static'.

import static com.pkg.global.GlobalConst.*;
Gaurav Raje
Ranch Hand

Joined: Jul 23, 2010
Posts: 136
Sun (Oracle now) has made an extra hard effort at not differentiating the sun packages(shipped with the jdk) and the classes which you write. If you look at the source of openjdk, every class is the same, regardless of whether it was written by you or by sun. So any rule which applies to your classes applies to theirs and vice versa.
So to answer your question... no its not true that static imports work only with sun;s classes
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
Welcome to the Ranch Shinil Mohan
Shinil Mohan
Ranch Hand

Joined: Aug 24, 2011
Posts: 37

Thanks Campbell ....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static Import in Java 5