• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

static import and enum

 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I see normal import for enum is working. e.g public enum is defined inside a
class and another package imports it in the following way:

import xyz.Abc.MyEnum;

where xyz is a package, Abc is a class and MyEnum is enclosed enum.

Along with this, static import works as well:

import static xyz.Abc.MyEnum;

I find is little confusing while "Whizlab explanation" says we can't do normal import on enum, because enclosed class enums are by default static.


Sorry for inconvenience if this question has been asked before


Thanks,
[ May 12, 2007: Message edited by: Chandra Bhatt ]
 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The normal import works just fine for enum becuase apart from being static members of the enclosing class, they are also a class by themselves. They are like a nested class within the outer class when declared inside another class. That is why the normal import works just fine for them , as it would for any other nested class.


we can't do normal import on enum, because enclosed class enums are by default static.



This statement by itself seems untrue, but might be true in context of the particular code example, like say if its asking for the most appropriate import syntax for enums or something....
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Megha,


This statement by itself seems untrue, but might be true in context of the particular code example, like say if its asking for the most appropriate import syntax for enums or something....



Question was "choose legal imports to compile the following code compile
and run without error"


Thanks,
 
So you made a portal in time and started grabbing people. This tiny ad thinks that's rude:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic