Nested interface

Can anybody make any sense of this?
I cannot do this:
interface Action {
     void run();
class SomeAction implements Action {
     public void run() { ? }
class Controller<A extends Action> {
     public interface Command {
       void doIt(A action);                                      // compile-time error
       void undoIt(A action);                                    // compile-time error
class SomeController implements Controller<SomeAction>.Command {   // compile-time error
     public void doIt(SomeAction action) { ? }
     public void undoIt(SomeAction action) { ? }
}But I can do that:
interface Action {
     void run();
class SomeAction implements Action {
     public void run() { ? }
class Controller<A extends Action> {
     public interface Command<A extends Action>  {
       void doIt(A action);
             void undoIt(A action);
class SomeController implements Controller.Command<SomeAction> {
       public void doIt(SomeAction action) { ? }
     public void undoIt(SomeAction action) { ? }
}Why?
After type erasure the Controller.Command interface boils down to the same thing either way, namely:
class Controller {
     public interface Command  {
       void doIt(Action action);
             void undoIt(Action action);
}I understand that type variables must not appear in static context of a parameterized class and that the first example is rejected for this reason. But, ... is there a really compelling reason?
It is even worse than in my code snippet. Using the prototype compiler I can refer to the nested interface in the second code sample as
Controller.Command<SomeAction>
Controller<SomeAction>.Command<SomeAction>
Controller<String>.Command<SomeAction>
Where is the point?

>
Looks like a bug to me. Your inner interface in the
first example is not a static context; therefore the
type variable should work there.My understanding is that nested interfaces ARE static (ie the one inner interface is shared by all instances of the enclosing class), and therefore the type variable's scope does NOT include the inner interfaces.
So its not a bug.
if you are not sure why we're all talking about whether the interfaces are static or not, it is because the draft spec says (section 2.2 near bottom of page 3)
The scope of a type parameter is all of the declared class, except any static members or initializers, but
including the type parameter section itself. Therefore, type parameters can appear as parts of their
own bounds, or as bounds of other type parameters declared in the same section.
However, whether the inner interfaces should be included under that broad clause, is debatable. (Well I think it's debatable, and despite bringing the issue up previously, no-one has debated the contrary point in this forum)
The debate could be ended by someone showing how the type system could be broken if an inner interface did reference a type variable of the enclosing class. Any takers?
In the absence of such proof, it would seem convenient if we didn't have to declare the type parameter in both the enclosing class and the inner interface.
In summary, what you observe is consistent with (Sun's understanding of) the draft spec. but I believe the spec itself (or Sun's interpretation), is open to discussion.
Bruce

Similar Messages

  • Static interface Vs Static nested interface declaration

    Hi,
    I have observed that static interface declaration is not allowed in Java. However static nested interface declaration is allowed.
    I could not understood reason behind this behavior.
    e.g.
    interface A{
         void AA();
         public static abstract interface Aa{
    } ........... this is allowed in Java.
    static interface d{
    } ...... This is not allowed in Java...
    I already know that static mean one for class and interface has only abstract method.
    Please let me know if any one know resign behind this.
    Thanks .

    Why don't you go to a Java forum?

  • Nested interfaces and abstract methods

    Consider the following design:
    interface ZIF_INTERFACE_A.
      methods METHOD_A.
    endinterface.
    interface ZIF_INTERFACE_B.
      interfaces ZIF_INTERFACE_A.
      methods METHOD_B.
    endinterface.
    class CLASS_A_B definition abstract.
    public section.
      interfaces ZIF_INTERFACE_B
        abstract methods METHOD_B.
      interfaces ZIF_INTERFACE_A
        abstract methods METHOD_A.
      methods METHOD_C.
    endclass.
    class CLASS_A_B implementation.
      method METHOD_C.
      endmethod.
    endclass.
    When trying to implement this design, the syntax check is giving me an error:
    The method "METHOD_A" was declared as not ABSTRACT in a previous INTERFACES statement.
    If I implement the design with Java (either using a public nested interface, or using interface inheritance) there is no problem declaring both the methods METHOD_A and METHOD_B as abstract in the CLASS_A_B class.
    So it seems to me this might be a bug in the ABAP Objects implementation. Or perhaps I am missing something else here? Does anyone have any suggestions?

    Hello,
    Nested interfaces
    When you include an IF in another IF both of them will exist on the same level, there is no concept of hierarchy. So when you add interface ZIF_B in the implementing class ZCL_A_B, the interface ZIF_A is also "included" in the relationship with the class ZCL_A_B implicitly.
    Just try to activate the code below & you'll get the error: "Implementation missing for method zif_interface_a~method_a":
    CLASS class_a_b DEFINITION ABSTRACT.
      PUBLIC SECTION.
    *    INTERFACES zif_interface_a
    *      ABSTRACT METHODS method_a.
        INTERFACES zif_interface_b
          ABSTRACT METHODS: method_b.
        METHODS method_c.
    ENDCLASS.                    "CLASS_A_B DEFINITION
    CLASS class_a_b DEFINITION ABSTRACT.
      PUBLIC SECTION.
        INTERFACES zif_interface_b
          ABSTRACT METHODS method_b.
        INTERFACES zif_interface_a
          ABSTRACT METHODS method_a.
        METHODS method_c.
    ENDCLASS.                    "CLASS_A_B DEFINITION
    So when the compiler is trying to compile your code it encounter implementation of ZIF_INTERFACE_B it finds that the "included interface" method ZIF_INTERFACE_Amethod_a is not abstract. So when you declare ZIF_INTERFACE_Amethod_a as "abstract" in the next line the compiler throws this error.
    So you need to define ZIF_INTERFACE_A~method_a as abstract, before defining ZIF_INTERFACE_B. Like this:
    CLASS class_a_b DEFINITION ABSTRACT.
      PUBLIC SECTION.
        INTERFACES zif_interface_a
          ABSTRACT METHODS method_a.
        INTERFACES zif_interface_b
          ABSTRACT METHODS method_b.
        METHODS method_c.
    ENDCLASS.                    "CLASS_A_B DEFINITION
    In this case the compiler treats method_a as abstract while checking ZIF_INTERFACE_B. Hence it doesn't throw any error.
    Hope i'm clear.
    BR,
    Suhas
    PS: Whenever i face any problem while creating local classes, i create a dummy class in the class builder to check

  • Nested interfaces for constants

    Dear java community,
    I had interface that have big amount of constants of different types:
    public interface ApplicationConrstants {
       String USER_CONSTANT_1 = "userConstant1 value";
       String USER_CONSTANT_2 = "userConstant2 value";
       String USER_CONSTANT_3 = "userConstant3 value";
       String BANK_CONSTANT_1 = "bankConstant1 value";
       String BANK_CONSTANT_2 = "bankConstant2 value";
    }I decided to create nested interfaces in this interface to collect similar constants in groups:
    public interface ApplicationConrstants {
       interface UserConrstants {
          String CONSTANT_1 = "userConstant1 value";
          String CONSTANT_2 = "userConstant2 value";
          String CONSTANT_3 = "userConstant3 value";
       interface BankConrstants {
          String CONSTANT_1 = "bankConstant1 value";
          String CONSTANT_2 = "bankConstant2 value";
    }What do you think about this approach?
    Thanks.

    define constants using:
    public final static type CONSTANT_NAME
    no point creating an interface for them

  • Cann't extend a inner class where as can Implement a nested Interface

    i cann't extend a inner class in some other outer class . Where as i can implement the nested Interface in some other class. Why????
    for example:-
    class ABC
    class Inner
    /* class body */
    interface TempInterface
    /* interfacebody */
    class OuterClass
    class InnerTwo extends ABC.inner //(line 1)Will give error
    class InnerTwo implements ABC.TempInterface //(line 2)Will run fine
    the line 1 is going to give compilation error i.e not in the scope but the line 2 will run fine .
    Both of the things are in the same class but giving 2 other results.
    I am not getting sufficient reasons for it.
    Can any one help me????
    Reagrds
    Arunabh

    As far as the language is concerned, the classonly
    exists in the context of an instance of theenclosing
    class.This still exhibits a class/object confusion to me.
    It should be 'instance only exists ...' or 'instance
    can only exist'. The class only exists in the
    scope of the enclosing class, but this is another
    issue.I'm not following what you're saying. The second sentence sounds like you're disagreeing with me. The last sentence sounds like you're agreeing with me.
    A non-static nested class is an instance member, just like an instance method or instance variable. As such, as far as the language is concerned, that class only exists in the context of an instance of the enlcosing class.It's not just instances of the nested class--its the class definition itself that only exists within the context of an instance of the enclosing class. That's why you have to do anEclosingIntstance.NestedClass and can't do EnclosingClass.NestedClass.

  • Interface inconsistency

    Hi All,
    I was just trying to fix the way the compiler does with the code below. Please have a look at this and let me know how '20' is printed on running it...
    It might look weird but, I tried this to understand the way the interface is compiled.
    Any explanation will be highly appreciated.
    interface inter
    int j = interinter.i + 10;
    interface interinter{
         int i = j + 10;
         int method();
    public class checkFloat implements inter{
    public static void main(String [] args){
         System.out.println("Inter " + inter.j);     
    *************************************************************

    This sounds theoritically perfect.
    As u know,
    1) The interface member variables are not initialized by default. i.e. Java compiler would not let you go with uninitialized variables. The value of x in ur ex., should not be given a 0.
    2) In my code, if I print interinter.inter.i the value is the same. i.e it prints 20.
    3) What surprise me is that...
    a) Is the nested interface loaded first or the outer interface loaded firstr

  • Use of declaring an interface inside an interface

    Hi
    Whats the use of declaring an interface inside an interface? I can make some guesses by my own but want to come up with some
    solid reasoning.
    So any view points are welcome
    public interface ParentInterface{
    interface ChildInterface{
    public void inside();
    thanks
    Harshit

    CeciNEstPasUnProgrammeur wrote:
    kajbj wrote:
    One reason could be that the outer interface has a method that takes a callback implementation as argument. The nested interface is in that case the contract that the callback method must implement. I don't see a reason to declare that callback interface at top level.That's what I meant. Although I see very few reasons (namely one - limited usage, which might change) not to declare it at top level, because you can't make it less visible, like one might do with an inner class implementing a public interface.
    There is no technical reason for it and no technical reason against it, and whether or not seems just to be a matter of personal taste.I agree. But it can also make it easier to navigate the code. Now people can see that the NotificationListener interface only is important if you are going to use or implement a processor (but that could kind of be done with packages as well)
    I just don't like the looks of "class Myclass implements SomeInterface.InnerInterface".Neither do I, and I would probably create an anonymous implementation that just delegates.

  • What are interfaces

    sir,
    plz explain me about interfaces, whare are they where r used in ABAP and explain with example.

    Hi Sandeep,
    Interfaces
    Classes, their instances (objects), and access to objects using reference variables form the basics of ABAP Objects. These means already allow you to model typical business applications, such as customers, orders, order items, invoices, and so on, using objects, and to implement solutions using ABAP Objects.
    However, it is often necessary for similar classes to provide similar functions that are coded differently in each class but which should provide a uniform point of contact for the user. For example, you might have two similar classes, savings account and check account, both of which have a method for calculating end of year charges. The interfaces and names of the methods are the same, but the actual implementation is different. The user of the classes and their instances must also be able to run the end of year method for all accounts, without having to worry about the actual type of each individual account.
    ABAP Objects makes this possible by using interfaces. Interfaces are independent structures that you can implement in a class to extend the scope of that class. The class-specific scope of a class is defined by its components and visibility sections. The public components of a class define its public scope, since all of its attributes and method parameters can be addressed by all users.
    Interfaces extend the scope of a class by adding their own components to its public section. This allows users to address different classes across different inheritance trees via a universal point of contact. Interface references allow users to address and use different classes in exactly the same way. Interfaces, along with inheritance, provide one of the pillars of polymorphism, since they allow a single method within an interface to behave differently in different classes.
    Defining Interfaces
    Like classes, you can define interfaces either globally in the Repository or locally in an ABAP program. For information about how to define local interfaces, refer to the Class Builder section of the ABAP Workbench Tools documentation. The definition of a local interface intf is enclosed in the statements:
    INTERFACE intf.
    ENDINTERFACE.
    The definition contains the declaration for all components (attributes, methods, events) of the interface. You can define the same components in an interface as in a class. The components of interfaces do not have to be assigned individually to a visibility section, since they automatically belong to the public section of the class in which the interface is implemented. Interfaces do not have an implementation part, since their methods are implemented in the class that implements the interface.
    Implementing Interfaces
    Unlike classes, interfaces do not have instances. Instead, interfaces are implemented by classes. To implement an interface in a class, use the statement
    INTERFACES intf.
    in the declaration part of the class. This statement may only appear in the public section of the class.
    When you implement an interface in a class, the components of the interface are added to the other components in the public section. A component icomp of an interface intf can be addressed as though it were a member of the class under the name intf~icomp.
    The class must implement the methods of all interfaces implemented in it. The implementation part of the class must contain a method implementation for each interface method imeth:
    METHOD intf~imeth.
    ENDMETHOD.
    Interfaces can be implemented by different classes. Each of these classes is extended by the same set of components. The methods of the interface can be implemented differently in each class. However, each class should keep the semantics of the interface. A method implementation should provide precisely that functionality which is required by the interface.
    Interfaces allow you to use different classes in a uniform way using interface references (polymorphism). For example, interfaces that are implemented in different classes extend the public scope of each class by the same set of components. If a class does not have any class-specific public components, the interfaces define the entire public face of the class.
    Interface References
    Reference variables allow you to access objects (refer to Working with Objects). Instead of creating reference variables with reference to a class, you can also define them with reference to an interface. This kind of reference variable can contain references to objects of classes that implement the corresponding interface.
    To define an interface reference, use the addition TYPE REF TO intf in the TYPES or DATA statement. intf must be an interface that has been declared to the program before the actual reference declaration occurs. A reference variable with the type interface reference is called an interface reference variable, or interface reference for short.
    An interface reference iref allows a user to use the form iref->icomp to address all visible interface components icomp of the object to which the object reference is pointing. It allows the user to access all of the components of the object that were added to its definition by the implementation of the interface.
    Addressing Objects Using Interface References
    If a class class implements an interface intf, you can use the following assignment between the class reference variable crefand an interface reference irefto make the interface reference in irefpoint to the same object as the class reference in cref:
    iref = cref
    If a class class implements an interface intf, you do not need to create a class reference variable cref with reference to the class first in order to create an object of the class class. Instead, you can use the TYPE addition in the CREATE OBJECT statement to create an instance of the class with an interface reference variable.
    CREATE OBJECT iref TYPE class.
    This creates an instance of the class classto which the reference in irefpoints.
    If the interface intf contains an instance attribute attr and an instance method meth, you can address the interface components as follows:
    Using the class reference variable cref:
    ·        To access an attribute attr: cref->intf~attr
    ·        To call a method meth: CALL METHOD cref->intf~meth
    Using the interface reference variable iref:
    ·        To access an attribute attr: iref->attr
    ·        To call a method meth: CALL METHOD iref->meth
    As far as the static components of interfaces are concerned, you can only use the interface name to access constants:
    To access a constant const: intf=>const
    For all other static components of an interface, you can only use object references or the class class that implements the interface:
    To access a static attribute attr: class=>intf~attr
    To call a static method meth: CALL METHOD class=>intf~meth
    Nesting Interfaces
    You can nest interfaces. An interface can contain one or more interfaces as its components, and these interfaces can, in turn, themselves contain interfaces. An interface which contains another interface is called a nested or a compound interface. An interface which is contained in another interface is referred to as the component interface. An interface which does not contain any nested interfaces is called an elementary interface.
    All interface components of a nested interface are on the same level. If a nested interface i3 contains the interface components i2 which are themselves nested and contain the interface components i1, then the components i1 become interface components of i3. Generally, a nested interface contains each interface component exactly once. Even if a component interface is used a second time as the component of another component interface, it still exists only once.
    If you want to nest interfaces, use the statement INTERFACES in an interface definition:
    INTERFACE i3.
      INTERFACES: i1, i2 ...
    ENDINTERFACE.
    Here, the interface i3 consists of its components as well as of the interfaces i1 and i2. The components of the component interfaces are not directly visible in the nested interface. In the above definition of i3, expressions like i1comp or i2compcannot be used, with the exception of the ALIAS statement.
    There are several ways how you can use the components of component interfaces:
    Using Alias Names
    You can use the ALIAS statement in interface definitions to assign alias names to the components of component interfaces. This makes these components visible in the interface definition.
    INTERFACE i2.
      INTERFACES i1.
      ALIASES alias21 FOR i1~comp1.
    ENDINTERFACE.
    INTERFACE i3.
      INTERFACES i2.
      ALIASES alias31 FOR i2~alias21.
      ALIASES alias32 FOR i2~comp2.
    ENDINTERFACE.
    Assigning Interface References
    You can assign interface references typed with reference to one of the component interfaces to interface references typed with reference to a nested interface. You can then use the interface references typed with reference to a component interface to address the components of the component interfaces.
    INTERFACE i2.
      INTERFACES i1.
    ENDINTERFACE.
    INTERFACE i3.
        INTERFACES i2.
    ENDINTERFACE.
    DATA: iref1 TYPE REF TO i1,
          iref2 TYPE REF TO i2,
          iref3 TYPE REF TO i3.
    iref2 = iref3.
    iref1 = iref2.
    ... iref1->comp1 ...
    ... iref2->comp2 ...
    The following expressions are not possible:
    ... iref2->i1~comp1 ...
    ... iref3->i2~comp2 ...
    Implementing Nested Interfaces in Classes
    When you implement a nested interface in a class, then all interfaces contained are implemented in the class at the same level, whatever their nesting depth. The class must then implement all methods.
    INTERFACE i2.
      INTERFACES i1.
    ENDINTERFACE.
    INTERFACE i3.
      INTERFACES i2.
    ENDINTERFACE.
    CLASS class DEFINITION.
      INTERFACES i3.
    ENDCLASS.
    CLASS class IMPLEMENTATION.
      METHOD i1~meth.
      ENDMETHOD.
    ENDCLASS.
    Use:
    DATA: cref TYPE REF TO class.
    ... cref->i1~comp1 ...
    ... cref->i2~comp2 ...
    ... cref->i3~comp3 ...
    Nested expressions such as cref->i3i2comp2 or cref->i3i2i3~comp3 are not possible. The nesting hierarchy is only important when you assign interface references to each other. You can assign class references for classes which implement a nested interface to all interface references typed with reference to an interface component contained. The interface references only know the components of their interface within the class.
    Interfaces and Inheritance
    As far as interfaces are concerned, polymorphism is based on the fact that each class implementing an interface can implement its methods in a different way. To the outside, however, all interface components look the same. As a result, interface references can point to objects of all classes which implement the associated interface.
    The concepts of interfaces and of inheritance are completely orthogonal. In the classes of an inheritance tree you can implement as many interfaces as required. However, you must pay attention to the fact that each interface can be implemented only once per inheritance tree. This ensures that each interface component has a unique name intf~icomp across the entire inheritance tree and is contained in all subclasses starting with the class that implements the interface.  Interface references that can point to a class of an inheritance tree can also point to all subclasses. Once they have been implemented, interface methods are fully-fledged components of a class and can be redefined in subclasses. However, you cannot declare interface methods as abstract or final in the definition of the interface.
    Reward points, if useful.
    Regards,
    Nitin.

  • JAXB anonymous complex types and inner interfaces

    When JAXB generates interfaces/classes for a schema with nested anonymous complex types, it nests the resultant interfaces/classes. Is there any way to force JAXB to put these nested interfaces/classes at the top level of the package instead?
    Note that if I specify a <class> binding, it changes the name of the inner interface/class, but doesn't change the fact that it's nested. It is my understanding that in JAXB Beta specifying a <class> binding for an anonymous complexType would in fact push it to the top level. Was this a bug, or is it a feature missing from 1.0, or am I misinformed about JAXB Beta?
    I realize that scope-wise it makes sense to generate nested anonymous complex types as inner classes, however it leads to highly unreadable code when dealing with deeply nested structures. I'm hoping someone knows of a way to workaround this issue without simply redefining the anonymous complex types as named complex types.
    Thanks,
    -Greg Merrill

    According to sec 4.4 "By default if xml schema component for which java content interface is to be generated is scoped within a complex type then the java content interface should appear nested within the content interface representing the complex type. ".
    So I doubt that worked with beta and you may have to represent this anonymous complex type as a named complex type to avoid the nesting.
    Regards,
    Bhakti

  • Why will inner interface be used?

    Our own web framework includes below code:
    public class MapExecutor<E extends Exception> {
         public static interface Accessor {
                  SqlMapClient client();
              LobHandler lob();
    }I don't know how handy inner interface is, any ideas? thanks.

    798885 wrote:
    I don't know how handy inner interface is, any ideas? thanks.There are many reasons for using a nested interface/class, but the most common ones are:
    1. It has no meaning outside the context/class in which it's defined.
    2. To distinguish it from another interface/class with the same name.
    3. To force clients to qualify it's name with it's enclosing class (eg, Map.Entry).
    Winston

  • Can anybody explain me what is interface

    hi gurus
    can anyone explain me what is interface
    tahnk you
    regards
    kals.

    hi
    Interfaces are independent structures that allow you to enhance the class-specific public points of contact by implementing them in classes.
    Interfaces can be defined globally in the R/3 repository or locally in ABAP program
    Can define exactly same components in Interfaces as in Classes
    Unlike classes, Interfaces do not have instances, instead they are implemented by classes
    Implemented using INTERFACES statement in the declaration part of the class
    INTERFACES statement must be included in the PUBLIC SECTION of the class
    Different classes that implement the same interface can all be addressed in the same way.
    Interface references allow users to address different classes in the same manner.
    Interfaces can also be nested.
          Interfaces are the basis for polymorphism in classes, because they allow a single interface method to behave differently in different classes.
    If an interface is implemented in the class, the interface components are added in the public section of the class.
    A component comp of an interface intf, implemented in a class, becomes a fully-fledged member of that class, with the name intf~comp.
    Classes that implement interfaces must implement all of their methods.
         METHOD intf~meth.
         ENDMETHOD.
    Interfaces allow you to use different classes in a uniform way (polymorphism).
    Interface References
    Creating Interface Reference Variables
          DATA obj TYPE REF TO intf.
    Using this reference variable, you can access any of the components defined in the interface
    Nested Interfaces
    Interface can include one or more interfaces as components, which can contain interfaces themselves.
    Compound Interface : It includes other interface as its component.
    Elementary Interface : It does not include any interface as a component.
    All interface components of a compound interface have the same level
    A component interface exists only once even if it is used once more as a component of another component interface.
    Aliases : It can be used to assign alias names to the components of component interfaces, thus making them visible within the interface definition.
                  ALIASES <alias name> FOR intf~comp.
    Where, intf  = interface name and comp = Component name
    Accessing Objects using Interface References
    It is also possible to directly generate an object to which the interface reference
          variable points initially. In this case, the TYPE addition of the statement CREATE OBJECT must be used to specify a class that implements the interface.               CREATE OBJECT iref TYPE class.
    If the interface intf contains an attribute attr and an instance method meth, you can address them as follows:
    Using the class reference variable:
    Accessing an attribute attr: cref->intf~attr
    Calling a method meth: CALL METHOD cref->intf~meth
    Using the interface reference variable:
    Accessing an attribute attr: iref->attr
    Calling a method meth: CALL METHOD iref->meth
    Accessing Static Components of Interfaces
    Use the name of the interface to access constants within an interface. 
    Accessing a constant const: intf=>const.
    To access the other static components of an interface, use an object reference or the class class that is implementing the interface. 
    Accessing a static attribute attr: class=>intf~attr.
    Calling a static method meth: CALL METHOD class=>intf~meth.

  • Does an interface extend Object ?

    1.Does an interface extend 'Object' ?
    If not,then how is it possible to type an Object
    to an interface ?
    for(Iterator i = m.entrySet().iterator();i.hasNext(); ){
         Map.Entry e = (Map.Entry) i.next(); // Object returned is typecasted
    }i.next() returns back type Object
    Entry is a nested interface within Map.
    2.How is Object being typecasted to an interface?

    bhuru_luthria wrote:
    1.Does an interface extend 'Object' ?
    If not,then how is it possible to type an Object
    to an interface ?
    for(Iterator i = m.entrySet().iterator();i.hasNext(); ){
         Map.Entry e = (Map.Entry) i.next(); // Object returned is typecasted
    }i.next() returns back type Object
    Entry is a nested interface within Map.
    2.How is Object being typecasted to an interface?Casting works at compile time if the object could be of the type indicated. The compiler doesn't know that the object pointed to by the result of next() won't be a Map.Entry, so it allows the cast.
    Casting works at compile time if the object actually is of the type indicated. In this case, the object IS-A Map.Entry (since it declares implements Map.Entry), so the cast succeeds.
    This has nothing to do with an interface extending object (which they don't). It's simply multiple inheritance of interface (or of type).

  • Interface visibility

    Hi,
    I want to know the visibility level of Interfaces. Can an Interface be declared private or protected? or Can it only have default and public access?
    Can an interface be declared within a class?
    All members of an interface are public by default?
    Pola

    codingMonkey wrote:
    While we're at it, what's the use of having nested interfaces?I've used interfaces nested in classes on a number of occasions.
    Sometimes nested/inner classes implement them. Sometimes they specify a callback to be passed to a method of the containing class.
    For example, suppose you are writing a command line processor where a different method is invoked for each keyword, you might do:
    private interface Comand {
        void doIt():
    private static Map<String,Command> commandMap = new HashMap<String, Command>(20);
    static {
        commandMap.put("exit", new Command() {
           public void doIt() {
               System.exit(0);
       ....

  • Enum declaration in a method

    An enum can be declared inside or outside a class, but can't be declared in a method.
    Can anyone tell that what is the problem with it. for what reason this restriction exist?
    Thanks in advance

    Karanjit is right. Nested interfaces and enums both are implicitly static. And their Constants are always (also when defined in top level) implicitly static. As we can't have static types inside a method we can't define enum in a method.
    I read in "Sun Certified Programmer for Java 5 Study Guide" written by Bert Bates and Kathy Sierra that if we have following enum:
    enum CoffeeSize { BIG, HUGE, OVERWHELMING }then we can think of this enum as a kind of class, that looks something (but not exactly) like this:
    class CoffeeSize {
         public static final CoffeeSize BIG = new CoffeeSize("BIG", 0);
         public static final CoffeeSize HUGE = new CoffeeSize("HUGE", 1);
         public static final CoffeeSize OVERWHELMING = new CoffeeSize(
                   "OVERWHELMING", 2);
         public CoffeeSize(String enumName, int index) {
              // stuff here
         public static void main(String[] args) {
              System.out.println(CoffeeSize.BIG);
    }Also see this code which is compilable:
    class HaveEnum {
         enum Colours {
              BLACK, WHITE
         static class StaClass {
              public static final StaClass sc = new StaClass();
         class InstClass {
              public final InstClass ic = new InstClass(); // can't be declared static
    public class General {
         public static void main(String[] args) {
              HaveEnum.StaClass hes = HaveEnum.StaClass.sc; // (1)
              HaveEnum.Colours col = HaveEnum.Colours.BLACK; // (2)
              HaveEnum he = new HaveEnum(); // (3)
              HaveEnum.InstClass hei = he.new InstClass().ic; // (4)
    }We can have enum constant BLACK in General class (at (2)) in similar way as StaClass constant sc (at (1)). If enum Colours were instant type like InstClass inner class then for having BLACK constant in General we would have to first instantiate HaveEnum class (like at (3)) and then using its object reference we could get BLACK constant (something like this) (like for InstClass at (4)):
    HaveEnum he = new HaveEnum();
    HaveEnum.Colours col = he.new Colours().BLACK;Note that main() method will throw StackOverflowError at runtime because (4) tries to recursively create another InstClass object.

  • Re: ActiveX problems with 3.0.F.2 (fwd)

    Forte has very specific requirements for ActiveX controls. We found out the
    hard way that Forte does not support the use of all ActiveX controls.
    Here is some information I received from Mark Cooper at Forte:
    With a bit more digging I found that ActiveX controls are required to adhere
    to two restrictions in the Forte environment. ActiveX controls are required
    to provide a single interface (and cannot include irrelevant nested
    interfaces) and must implement Apartment model threading (technote 11344).
    You can use the OLE-Com Object Viewer to determine whether a control
    fulfills both of these requirements.
    Hope this helps. As I understand it, a future release (3G or 4???) will have
    better support of ActiveX controls. But in the mean time you are stuck to
    these limitations.
    Regards,
    Jason Carpenter
    CSC Consulting & Systems Integration
    [email protected]
    3811 Turtle Creek Blvd.
    20th Floor
    Dallas, TX 75219
    214.520.0555

    Forte has very specific requirements for ActiveX controls. We found out the
    hard way that Forte does not support the use of all ActiveX controls.
    Here is some information I received from Mark Cooper at Forte:
    With a bit more digging I found that ActiveX controls are required to adhere
    to two restrictions in the Forte environment. ActiveX controls are required
    to provide a single interface (and cannot include irrelevant nested
    interfaces) and must implement Apartment model threading (technote 11344).
    You can use the OLE-Com Object Viewer to determine whether a control
    fulfills both of these requirements.
    Hope this helps. As I understand it, a future release (3G or 4???) will have
    better support of ActiveX controls. But in the mean time you are stuck to
    these limitations.
    Regards,
    Jason Carpenter
    CSC Consulting & Systems Integration
    [email protected]
    3811 Turtle Creek Blvd.
    20th Floor
    Dallas, TX 75219
    214.520.0555

Maybe you are looking for

  • Error message -70012 A valid DVD drive could not be found.

    For several months now we cannot use the DVD player. After inserting a DVD- new or otherwise, it makes a bit of noise, then spits the dvd back out. Help needed for non tech-savvy person please!

  • How to catch events on user tables forms?

    Hi all, Is there any way to catch the events on user defined tables' form which opens from Tools-User Tables? The form Id we get is not unique so we can't initialize the form with that ID or put it in  an If  loop for pval.formUId. any clues? Thanks

  • Clearing Data Buffer Pools

    Is it possible to clear the buffer pool in Oracle without bouncing the database? We are configuring our database to use the keep buffer pools, and I wanted to test the performance improvements with pinning different tables into the keep buffer. Unfor

  • Clarification regarding static blocks.

    I can understand from this about the static initialization block. I just need one clarification. What is the difference between the blocks with and without the 'static' keyword? For eg., the following code prints 'Hello' class ClassWithStaticBlock {

  • Log Out Behavior - Users appear to stay logged in

    I cannot get a user to logout using the Log Out User behavior. I created a restricted page which displays the user's name once logged in, however when the user logs out and a different user id is used, the restricted page returns the first user's id.