Static interface functions

Hi everyone..
I have a class Tourist, which implements an interface named GenericUser. The former implements a static function "SF" but i cannot define "SF" as static in the interface. Any ideas? Anyone out there? :)

Here's how it would be called...
String retValue = GenericUser.getUserResponse();
And therein lies the problem. It will try to call GenericUser's getUserResponse, not that of any implementing class. How could it possibly even know which class' method to call with what you've got.
You might think to try something like this: GenericUser gu = new GenericUserImpl();
gu.getUserResponse(); But that still won't help. If getUserResponse were non-static, it would call GenericUserImpl's version of that methhod.
But for satic methods, which class' version is called is determined by the compile-time type of the reference (GenericUser), NOT the runtime type of the object.
In short: Static methods are not polymorphic. That's just a rule of the Java language.

Similar Messages

  • Static Class Function vs. Instance Variables

    I'm making a Wheel class to spin the wheels on some toy
    trains as they move back and forth.
    Each wheel on the train is an instance of the Wheel class and
    there are several of them.
    I thought it would be great to just have a static class
    function to tell all the Wheels to start turning:
    Wheel.go();
    The Wheel class keeps a static array of all of its instances
    so I thought I would just loop through all of those instances and
    issue the wheelInstance.roll() method.
    So far it all works. But I was planning to use a setInterval
    to call the roll() method and each instance has its own rollID
    property that I would like to assign the setInterval ID to. Here is
    the problem.
    Since the rollID is an instance property I can't access them
    from a static class function. Is there any way to do this?
    Currently I"m just using an onEnterFrame which doesn't require me
    to use the instance properties.

    Technically yes, realistically for this class no.A
    class will probably take several hundred bytes at
    least to load, with no data of your own. So adding4
    bytes for a int is less than 1% of the total size.
    And if you are loading millions of differentclasses
    then you should rethink your design.If you don't instantiate the class when you reference
    a static variable why would you consume memory for the
    class other than the variable itself? I don't
    understand what you are talking about with the
    "millions of different classes", it's not germane to
    the question. Bottom line, referencing a static
    variable more than once will save memory.Using a class, static or by instance, requires that the class be loaded. A loaded class creates, at the very least, an instance of java.lang.Class. Any static members of the class are in addition to the storage space needed for the instance of java.lang.Class and for any internal storage needed by the JVM in addition to that.
    Thus if one has a static data member when the class is used in any way, the static data member takes storage space. However a member (non-static) does not take storage space.
    Of course the meta data for the member could take as much space as the static member so the point could be moot. Is that what you were referring to?

  • Static class functions: PLS-00801: internal error [phd_get_defn:D_S_ED:LHS]

    Any ideas why this would generate an internal error - referring to a static class function in that class constructor's parameter signature?
    Test case (on 11.2.0.2) as follows:
    SQL> create or replace type TMyObject is object(
      2          id      integer,
      3          name    varchar2(30),
      4 
      5          static function DefaultID return integer,
      6          static function DefaultName return varchar2,
      7 
      8          constructor function TMyObject(
      9                  objID integer default TMyObject.DefaultID(), objName varchar2 default TMyObject.DefaultName()
    10          )return self as result
    11  );
    12  /
    Type created.
    SQL>
    SQL> create or replace type body TMyObject is
      2 
      3          static function DefaultID return integer is
      4          begin
      5                  return( 0 );
      6          end;
      7 
      8          static function DefaultName return varchar2 is
      9          begin
    10                  return( 'foo' );
    11          end;
    12 
    13          constructor function TMyObject(
    14                  objID integer default TMyObject.DefaultID(), objName varchar2 default TMyObject.DefaultName()
    15          )return self as result is
    16          begin
    17                  self.id := objId;
    18                  self.name := objName;
    19                  return;
    20          end;
    21 
    22  end;
    23  /
    Type body created.
    SQL>
    SQL> declare
      2          obj     TMyObject;
      3  begin
      4          obj := new TMyObject();
      5  end;
      6  /
    declare
    ERROR at line 1:
    ORA-06550: line 0, column 0:
    PLS-00801: internal error [phd_get_defn:D_S_ED:LHS]If the static class functions are removed from the constructor and applied instead inside the constructor body, it works without error. Likewise you can call the constructor with the static class functions as parameters, without an internal error resulting.
    SQL> create or replace type TMyObject is object(
      2          id      integer,
      3          name    varchar2(30),
      4 
      5          static function DefaultID return integer,
      6          static function DefaultName return varchar2,
      7 
      8          constructor function TMyObject(
      9                  objID integer default null, objName varchar2 default null
    10          )return self as result
    11  );
    12  /
    Type created.
    SQL>
    SQL> create or replace type body TMyObject is
      2 
      3          static function DefaultID return integer is
      4          begin
      5                  return( 0 );
      6          end;
      7 
      8          static function DefaultName return varchar2 is
      9          begin
    10                  return( 'foo' );
    11          end;
    12 
    13          constructor function TMyObject(
    14                  objID integer default null, objName varchar2 default null
    15          )return self as result is
    16          begin
    17                  self.id := nvl( objId, TMyObject.DefaultID() );
    18                  self.name := nvl( objName, TMyObject.DefaultName() );
    19                  return;
    20          end;
    21 
    22  end;
    23  /
    Type body created.
    SQL>
    SQL> declare
      2          obj     TMyObject;
      3  begin
      4          obj := new TMyObject();
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> declare
      2          obj     TMyObject;
      3  begin
      4          obj := new TMyObject(
      5                          objID => TMyObject.DefaultID(),
      6                          objName => TMyObject.DefaultName()
      7                  );
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    SQL> Had a quick look on support.oracle.com and did not turn up any specific notes dealing with the use of static class functions in the parameter signature of the constructor. Known issue? Any other workaround besides the one above?

    Hi,
    there is a bug: "Bug 8470406: OBJECT INSTANCE CREATION FAILS WITH ERROR PLS-00801 IN 11GR1", it shows the behaviour in 11g but not in 10.2. It gives exactly the symptoms you also see, move it to the body and it works. But there is no solution/patch given.
    Herald ten Dam
    http://htendam.wordpress.com

  • 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?

  • Sun Studio cc includes unused static inline functions in object file

    While trying to compile some code originally compiled with GCC I run into a linking problem. My problem seems to be caused by that GCC does not include unused static inline functions in the object files while cc does. The following simple example can be used for illustrating this:
    void foo();
    static inline void bar()
      foo();
    int main()
    }This program compiles and links without any problems using GCC and Sun Studio 12 CC (the C++ compiler) but fails to link using Sun Studio 12 cc:
    khepri%> cc staticinline.c
    Undefined first referenced
    symbol in file
    foo staticinline.o
    ld: fatal: Symbol referencing errors. No output written to a.out
    It is probably fine of cc to include foo() in the object file (although not necessary?). My questions are:
    1. Are there any reasons for why cc includes unused static inline functions in the object file while CC does not?
    2. Are there any ways or options to tell cc to not include unused static inline functions in the object file?
    In the example above this is easy to fix by just removing or #ifdef away the code but the original code where I have this problem is not maintained by me and the static inline functions are in header files that get included in multiple C files and in some of these the functions are used.
    Thanks,
    Olav

    olavsa wrote:
    1. Are there any reasons for why cc includes unused static inline functions in the object file while CC does not?
    2. Are there any ways or options to tell cc to not include unused static inline functions in the object file?Removing dead code is an optimization, so you need at least -xO1 for that.

  • Is it possible to call module component's function through interface function

    Hi,
         I see this in the livedocs.
    "In general, if you want to set properties on controls in the module by using external values, you should create variables that are bindable. You then set the values of those variables in the interface’s implemented methods. If you try to set properties of the module’s controls directly by using external values, the controls might not be instantiated by the time the module is loaded and the attempt to set the properties might fail."
         I have an extended component in a module. I need to call that component's funcion from the interface function. i.e My main appication call the interface funcion, and that interface funcion has to call the component's funcion. Is it possible. I get error that the component is null, if I try this. Is there any way to do this.
         Thanks in advance.

    I accomplished this, by dispatching a event from the module, and handling it in the module itself. In the handler I am able to access the component. However it is possible only when I use ModuleLoader. I tried the same using ModuleManager. It didnt work. I am adding the listener in creationComplete event. The event was triggered properly. But the listener was not invoked.
    Below is the TestModule i used. In this setLabel is the implemented function.
    <mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark" implements="TestInterface" creationComplete="onCreate()"
               xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" width="400" height="300">
        <fx:Script>
            <![CDATA[
                [Bindable] public var labelText:String = 'Initial Text';
                public function onCreate():void {               
                    this.addEventListener("test",testListener);
                public function setLabel(s:String):void {
                    trace(getQualifiedClassName(parentDocument));
                    this.labelText = s;       
                    triggerEvent();
                public function triggerEvent():void {
                    trace('triggering event');
                    dispatchEvent(new Event("test",true));
                public function testListener(event:Event):void {
                    trace('event caught');
                    trace(moduleLabel.text);
            ]]>
        </fx:Script>
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <mx:Label id="moduleLabel" text="{labelText}"/>
    </mx:Module>
    With ModuleLoader I get the following output in console, when the setLabel function is called
    ModuleTest
    triggering event
    event caught
    test
    With ModuleManger,I get the following output. The event listener is not invoked.
    null
    triggering event
    Also while trying different options, in between I tried using parentDocument. I added the below line in the interface function.
    trace(getQualifiedClassName(parentDocument));
    This line printed the correct parent class name, while using ModuleLoader. But printed null with ModuleManager.
    Following are the functions in main application to load the module using module manager.
                public function onCreate():void {
                    loadTestModule();
                public function loadTestModule():void {       
                    var url:String = '';
                    url += 'TestModule.swf';
                    modInfo = ModuleManager.getModule(url);
                    modInfo.addEventListener(ModuleEvent.ERROR,moduleReady);
                    modInfo.addEventListener(ModuleEvent.READY,moduleReady);
                    modInfo.load(null, null, null, moduleFactory);
                public function moduleReady(event:ModuleEvent):void {               
                    if (event.type == ModuleEvent.ERROR) {
                        trace(event.errorText);
                    if (event.type == ModuleEvent.READY) {
                        mod = modInfo.factory.create() as TestInterface;
                        var el:IVisualElement = modInfo.factory.create() as IVisualElement;
                        this.addElement(el);                   
    Am I missing something when I use ModuleManager.

  • Using FPGA Interface Functions pallete

    Hi,
    I am using PCI-5640R  and PXI-5600. I want to use "Scaled Window" and "FFT" exspress VIs of "FPGA Math & Analysis" Functions Pallete in my "FPGA VI" and "FFT to Spectrum" VI  of "FPGA Interface" in my "Host VI".
    Can any one post some example code in which these three subVIs are used.
    Thanks in advance.
    Regards,
    Rashid  
    Solved!
    Go to Solution.

    The answer to this question is available at 
    http://forums.ni.com/t5/IF-RIO/Using-FFT-to-Spectrum-SubVI-of-FPGA-Interface-Functions-pallete/td-p/...

  • Static interfaces

    Hi everybody,
    I could not find eny information about static interfaces (not static members of an interfaces - static interfaces itself).
    Could anybody give me some information about it ?
    I came accross with many interfaces wich are declared as:
    public static interface name_of_interface
    Thank you for all the answers.
    Adrian

    Inner interfaces can be declared static.Well, there you go. I should Google myself before answering!
    Never thought of inner interfaces.
    Cheers!

  • Why a static class can implements a non-static interface?

    public class Test {
         interface II {
              public void foo();
         static class Impl implements II {
              public void foo() {
                   System.out.println("foo");
    }Why a static class can implements a non-static interface?
    In my mind, static members cann't "use" non-static members.

    Why a static class can implements a
    non-static interface?There's no such thing as a non-static member interface. They are always static even if you don't declare them as such.
    An interface defines, well, a public interface to be implemented. It doesn't matter whether it is implemented by a static nested class or by an inner class (or by any class at all). It wouldn't make sense to enforce that it should be one or the other, since the difference between a static and non-static class is surely an irrelevant detail to the client code of the interface.
    In my mind, static members cann't "use" non-static
    members.
    http://java.sun.com/docs/books/jls/third_edition/html/classes.html#246026
    Member interfaces are always implicitly static. It is permitted but not required for the declaration of a member interface to explicitly list the static modifier.

  • Using static interface inner class.. how?

    Can anyone tell me how I'm able to use an inner class that is a static interface?
    Specifically I'm getting DocumentEvents through a DocumentListener..
    Then within DocumentEvents there is an inner class which is a static interface called:
    DocumentEvent.ElementChange, I'm trying to use the methods contained within the interface ElementChange.
    Can anyone throw a helping hand as to how I go about this?
    Thanks :)

    public class A ... {
    public static interface B {
    }Just creates a public interface called A.B
    How are you supposed to use this with your DocumentEvent? I can't say

  • [SOLVED] Passing a non-static member function as a function pointer

    I need to pass a function pointer to a public method to a system call, nftw() to be precise.
    I know that member functions don't match the required signature because of the hidden 'this' pointer, but
    the only way to work around that is by using a small wrapper function that makes use of a global variable (the object of which I want to call the method).
    Speaking in code, this is the way I've solved the problem currently:
    // create a global variable here
    static MyObject obj;
    static int myObject_method_wrapper(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) {
    return obj.handleDirEntry(fpath, sb, tflag, ftwbuf);
    // somewhere in main()
    nftw(walkroot, myObject_method_wrapper, 20, FTW_PHYS);
    Now, my question: Can't this be done without a global instance of MyObject? It is pointed out here that other ways are existent, but sadly they are not mentioned.
    Glad if someone could help me out!
    Last edited by n0stradamus (2012-04-24 22:59:47)

    I think you are stuck:
    1. You are not in control of the interface (of nftw), and furthermore,
    2. You are not in control of any of the parameters sent to the callback.
    nftw has no idea which one of your objects it is supposed to reference, and
    there's no apparent way to tell it.
    But given this situation, are you sure it makes sense to use a non-static
    member?  It seems kind of strange to me-- any instance-specific data is
    necessarily going to be independent of the function calls!  So even if you
    engineer something to avoid using a global, whatever you engineer is still
    going to involve some *arbitrary* instance of your class (e.g. peterb's
    solution, which uses the most recently created instance).  The arbitrary-ness
    doesn't feel right, since it sort of implicitly says that none of the instance
    data is important.  No important instance-specific data sounds like static...

  • Static Interface Methods in ABAP

    Hello,
    I'd like to know what sense it makes to define static methods in an interface.
    My understanding is, that an interface can only be used with an instance of a class implementing that interface. So I always need to have an instance and thus, static methods are not needed.
    But ABAP-OO (in contrast to Java, for example) allows that, so maybe there is some need for that?
    Thanks for your help, best regards,
    Timo Wolf.

    Hi,
    As you know that static methods are not instance- specific. Hence when a class implements an interface, the methods defined as static do not require an instance-specific call. Rather they are called as CLASSNAME=>INTREFACE_NAME~STATIC_METHOD_NAME. You do not need an instance to access them.
    The only purpose of declaring a method as STATIC in interface definition is to create an agreement that a particular method will not depend on an instance to work. When a class implements the interface, calls to this method will be as mentioned above.
    <b>
    As far as the static components of interfaces are concerned, you can only use the interface name to access constants:
    Addressing 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:
    Addressing a static attribute <attr>: <class>=><intf~attr>
    Calling a static method <meth>: CALL METHOD <class>=><intf~meth>
    </b>
    Hope this helps.
    Regards
    Message was edited by: Shehryar Khan
    Message was edited by: Shehryar Khan

  • Compiler error with default arguments and static template function

    Hi 
    The following does not compile with visual studio 2010 sp1, and compiles with gcc.
    #include <string>
    class A
    public:
       template<class T>
       static T& Get(const std::wstring&);
    class B
     public:
      void f(
        double d,
        double c =A::Get<double>(L"test"));
    int main()
        B b;
        b.f(5);
    It gives me the following error 
    error C2783: 'T & A::Get(const wchar_t *)' : could not deduce template argument for 'T'
    If I change Get to be global function and not static function of A, it compiles.

    It seems to be a compiler bug.  It fails in VS2012, but compiles in VS2013.
    For completion sake, the problem exists if A is a namespace containing Get.  But not if Get is global.
    The only solutions I can see are try to workaround the problem (make Get global) or upgrade to a newer version of VS.

  • Static LOV functions differently in 9.0.2 from 9.0.1

    In my previous Portal applications under IAS 9.0.1 I had several static LOV's that contained the following structure:
    DISPLAY VALUE RETURN VALUE
    Login User Name #PORTAL.wwctx_api.get_user
    This worked as expected, the user sees the display of 'Login User Name' in a drop down list on a form, but the users login name was actually inserted into the table when Insert is selected.
    I've since upgraded IAS to 9.0.2 (no patchsets installed)
    This same LOV no longer works. What gets insert into the table is the string "PORTAL.wwctx_api.get_user" and not the users name, as before.
    I know I can kluge something similar into a dynamic LOV but does anyone know why this function call no longer works? I have several similar LOV's that get sequence number nextval's in a similar fashion and they no longer work either.
    Thanks

    A TAR has been created concerning this issue, 2841152.996. If anyone has had similar results, please review it at http://metalink.oracle.com/metalink/plsql/tar_main.single_tar?p_tarNumber=2841152.996&p_countryCode=840&p_show=Show++

  • Apply static method requirements on class (Static interface methods)?

    I have a set of classes where is class is identified with a unique ID number. So each class has a public static int getId() method. Each class also has either a constructor that takes a byte array or a static factory method that takes a byte array.
    I would like to maintain a hashmap of these classes keyed to the ID's however I am not sure how to have some interface of abstract parent class that requires each of these classes to implement these static methods.
    What I was hoping to do was something like this>>>
         public interface MyClasses{
              static MyClasses createInstance(byte[] data);
         HashMap<Integer, MyClasses> map;
         public void init() {
              map = new HashMap<Integer, MyClasses>();
              map.put(Class1.getId(), Class1.class);
              map.put(Class2.getId(), Class2.class);
         public void createInstance (int id, byte[] data) {
              map.get(id).createInstance(data);
         }Is there some way I could do this?

    What about something like this?
    public interface Initializable
         public void initialize(byte[] data);
    public class Factory
         private final Map<Integer, Initializable> map = new HashMap<Integer, Initializable>();
            public void registerClass(int id, Class klass)
                    if (! Initializable.class.isAssignableFrom(klass))
                             // you may also want to ensure the class declares a parameterless constructor
                             throw new IllegalArgumentException("duff class");
                    if (this.map.keySet().contains(id))
                             throw new IllegalArgumentException("duff id");
              this.map.put(id, klass);
         public Initializable createInstance(int id, byte[] data)
                    // need some exception handling of course
              Initializable i = map.get(id).newInstance();
                    i.initialize(data);
                    return i;
    }

Maybe you are looking for

  • Dealing with an empty string parameter

    I'd think this should be simple but is driving me nuts. I have a string parameter (lets call it Foo) that is being passed from my C# application to a CR subreport. For this parameter field I have a formula associated with "Display String" similar to

  • Process chain questions

    Hai  All,            I designed a process chain with data flow like this: R/3>ODS1>ODS2>Cube. The process chain sequence is: Start>>Load data>>activate ODS1 data>>load data to ODS2>>activate ODS2 data>>delete index>>load data to cube.            My p

  • Write XML file in application server

    Experts, I'm using a transformation to generate a xml file:   CALL TRANSFORMATION zdatafechomes   SOURCE ficheiroexecucao = gt_source[]   RESULT XML  xml_result. It's working fine. But i'm having problems in putting the "xml_result" (it's a type xtri

  • Plz helP me about the new FW (software) v4.0750.31...

    plz help me i was update new FW v4.0750.31.2.1 but found too bugs in music player i cant save the preset and the sogs was download in memory always bad file when i play it. and the camera light is very little and not pure. plz I wanna the old version

  • Using Oracle Service Registry without SOA Suite

    I am trying to use the Oracle Service Registry without having SOA Suite as all I want is to simply publish a web service for an experiment. I have : JDeveloper 10.1.3.3 Oracle Database 10g Getting problem in Installing Service Registry. Do I need to