• 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

Question on Static import!!

 
Ranch Hand
Posts: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
static imports:
===============

 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nice question. Brett's Devloper notes has a good explanation

1 is the answer The same question could be extended to static methods.
 
Krishna Srinivasan
Ranch Hand
Posts: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surprising Static Imports
 
Krishna Srinivasan
Ranch Hand
Posts: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
few tips on static import:

Two types of static import declarations:

1)single-type import declaration.
example:
import static Enum.EnumMember.Java;
2)static import on demand.
example:
import static Enum.EnumMember.*;


On-demand-static import never shadow the previous imports declarations.
example:
import static Enum.EnumMember.Java;
import static Enum1.EnumMember.*;

In the above example both the enum type has the variable Java.When we are usiing
the on-demand-static-import(import static Enum.EnumMember1.* .It will not shadow
the previous declaration import static Enum.EnumMember.Java;

But two single-type static imports trying to import the same variable, the compile
time error occurs.

example:
import static Enum.EnumMember.Java;
import static Enum1.EnumMember.Java;
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic