• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Static Import in Java 5

 
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 37
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.*;
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch Shinil Mohan
 
Shinil Mohan
Ranch Hand
Posts: 37
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Campbell ....
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic