How can a custom class call a function in "parent" class?

Say I have an application (ultrasimplified):
public class myApp {
myClass mc;
boolean foo=false;
public static void main(String[] args) {
mc = new myClass();
public static void myFunc(boolean blah) {
foo=blah;
in a separate .java file where my questions lie:
public class myClass {
boolean bar=true;
public void myClass() {
// this is wrong, but how would I do this:
foo = bar; // foo in myApp set to true
// or how would I call "myFunc()" in myApp from this class:
myFunc(bar);
my problem is that I've created a new class that I share between two applications so I could share the code. However, I want this class I created to call a function in the application class that instanciated it. Or alternatively, I would like to set a variable in the class that instanciated myClass.
How would go about this? I've used the "this" parameter in applets to pass the parent class to an inner class, but main() in applications doesn't allow the non-static "this":
myClass my = new myClass(this);
Is there something similar I can do?

You can let MyApp implement an interface and refer to that object in MyClass:
class MyApp implements Something {
main() {
MyApp app = new MyApp();
MyClass mc = new MyClass(app);
public void foo() { }
class MyClass {
Something app;
MyClass(Something app) {
this.app = app;
app.foo();
interface Something {
public void foo();
Better yet, you can let MyApp extend an abstract class that defines foo(). Then MyApp can override the foo() method. If later on, the abstract class needs to add a bar() method then default implementation can be done in the abstract class. If you make it an interface then all implementing classes will have to be updated to implement the new method.

Similar Messages

  • How can I debug the Call Library Function at run-time

    I've written a VI using the CLF to call a DLL which was compiled off-site by another engineer using MSVC. Even though the VI runs without flagging any errors, the VI is not doing what I expect. Is there any way of finding out if the DLL is been called correctly? The first function that is called doesn't return any value, but I think that it should. Does this mean that the DLL is not being called correctly? Note also that the DLL works fine with a JAVA GUI.

    Make sure that you are specifying the proper function prototype in the call library function. If you are slightly off the call will not work properly. Ask the offsite engineer to provide you with this data. Another tip is to build the dll with the option to show front panel when called. You can actually popup the dll like you would a subvi. If you design it with test indicators showing on the front panel that is a great way to determine if it is working. Hope this helps.
    BJD1613
    Lead Test Tools Development Engineer
    Philips Respironics
    Certified LV Architect / Instructor

  • SOLVED: How can I use or call a function that returns %ROWTYPE?

    Hi
    edit: you can probably skip all this guff and go straight to the bottom...In the end this is probably just a question of how to use a function that returns a %rowtype.  Thanks.
    Currently reading Feuerstein's tome, 5th ed. I've downloaded and run the file genaa.sp, which is a code generator. Specifically, you feed it a table name and it generates code (package header and package body) that will create a cache of the specified table's contents.
    So, I ran:
    HR@XE> @"C:\Documents and Settings\Jason\My Documents\Work\SQL\OPP5.WEB.CODE\OPP5.WEB.CODE\genaa.sp"
    749  /
    Procedure created.
    HR@XE> exec genaa('EMPLOYEES');which generated a nice bunch of code, viz:
    create or replace package EMPLOYEES_cache is
        function onerow ( EMPLOYEE_ID_in IN HR.EMPLOYEES.EMPLOYEE_ID%TYPE) return HR.EMPLOYEES%ROWTYPE;
        function onerow_by_EMP_EMAIL_UK (EMAIL_in IN HR.EMPLOYEES.EMAIL%TYPE) return HR.EMPLOYEES%ROWTYPE;
        procedure test;
    end EMPLOYEES_cache;
    create or replace package body EMPLOYEES_cache is
        TYPE EMPLOYEES_aat IS TABLE OF HR.EMPLOYEES%ROWTYPE INDEX BY PLS_INTEGER;
        EMP_EMP_ID_PK_aa EMPLOYEES_aat;
        TYPE EMP_EMAIL_UK_aat IS TABLE OF HR.EMPLOYEES.EMPLOYEE_ID%TYPE INDEX BY HR.EMPLOYEES.EMAIL%TYPE;
        EMP_EMAIL_UK_aa EMP_EMAIL_UK_aat;
        function onerow ( EMPLOYEE_ID_in IN HR.EMPLOYEES.EMPLOYEE_ID%TYPE)
            return HR.EMPLOYEES%ROWTYPE is
            begin
                return EMP_EMP_ID_PK_aa (EMPLOYEE_ID_in);
            end;
        function onerow_by_EMP_EMAIL_UK (EMAIL_in IN HR.EMPLOYEES.EMAIL%TYPE)
            return HR.EMPLOYEES%ROWTYPE is
            begin
                return EMP_EMP_ID_PK_aa (EMP_EMAIL_UK_aa (EMAIL_in));
            end;
        procedure load_arrays is
            begin
                FOR rec IN (SELECT * FROM HR.EMPLOYEES)
                LOOP
                    EMP_EMP_ID_PK_aa(rec.EMPLOYEE_ID) := rec;
                    EMP_EMAIL_UK_aa(rec.EMAIL) := rec.EMPLOYEE_ID;
                end loop;
            END load_arrays;
        procedure test is
            pky_rec HR.EMPLOYEES%ROWTYPE;
            EMP_EMAIL_UK_aa_rec HR.EMPLOYEES%ROWTYPE;
            begin
                for rec in (select * from HR.EMPLOYEES) loop
                    pky_rec := onerow (rec.EMPLOYEE_ID);
                    EMP_EMAIL_UK_aa_rec := onerow_by_EMP_EMAIL_UK (rec.EMAIL);
                    if rec.EMPLOYEE_ID = EMP_EMAIL_UK_aa_rec.EMPLOYEE_ID then
                        dbms_output.put_line ('EMP_EMAIL_UK  lookup OK');
                    else
                        dbms_output.put_line ('EMP_EMAIL_UK  lookup NOT OK');
                    end if;
                end loop;
            end test;
        BEGIN
            load_arrays;
        end EMPLOYEES_cache;
    /which I have run successfully:
    HR@XE> @"C:\Documents and Settings\Jason\My Documents\Work\SQL\EMPLOYEES_CACHE.sql"
    Package created.
    Package body created.I am now trying to use the functionality within the package.
    I have figured out that the section
        BEGIN
            load_arrays;
        end EMPLOYEES_cache;
    /is the initialization section, and my understanding is that this is supposed to run when any of the package variables or functions are referenced. Is that correct?
    With that in mind, I'm trying to call the onerow() function, but it's not working:
    HR@XE> select onerow(100) from dual;
    select onerow(100) from dual
    ERROR at line 1:
    ORA-00904: "ONEROW": invalid identifier
    HR@XE> select employees_cache.onerow(100) from dual;
    select employees_cache.onerow(100) from dual
    ERROR at line 1:
    ORA-06553: PLS-801: internal error [55018]
    HR@XE> select table(employees_cache.onerow(100)) from dual;
    select table(employees_cache.onerow(100)) from dual
    ERROR at line 1:
    ORA-00936: missing expressionHe provides the code genaa.sp, and a very brief description of what it does, but doesn't tell us how to run the generated code!
    Now, I have just done some googling, and it seems that what I am trying to do isn't possible. Apparently %ROWTYPE is PL/SQL, and not understood by SQL, so you can't call onerow() from sql. Correct?
    So I try wrapping the call in an exec:
    HR@XE> exec select employees_cache.onerow(100) from dual;
    BEGIN select employees_cache.onerow(100) from dual; END;
    ERROR at line 1:
    ORA-06550: line 1, column 30:
    PLS-00382: expression is of wrong type
    ORA-06550: line 1, column 7:
    PLS-00428: an INTO clause is expected in this SELECT statement
    HR@XE> exec select table(employees_cache.onerow(100)) from dual;
    BEGIN select table(employees_cache.onerow(100)) from dual; END;
    ERROR at line 1:
    ORA-06550: line 1, column 14:
    PL/SQL: ORA-00936: missing expression
    ORA-06550: line 1, column 7:
    PL/SQL: SQL Statement ignored
    HR@XE> exec employees_cache.onerow(100)
    BEGIN employees_cache.onerow(100); END;
    ERROR at line 1:
    ORA-06550: line 1, column 7:
    PLS-00221: 'ONEROW' is not a procedure or is undefined
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignoredNo joy.
    Of course, now that I'm looking at it again, it seems that the way to go is indicated by the first error:
    PLS-00428: an INTO clause is expected in this SELECT statement
    So am I supposed to create a type of EMPLOYEES%ROWTYPE in a PL/SQL procedure, and the idea of this code, is that the first call to onerow() runs the initialiation code, which populates the cache, and all subsequent calls to onerow() (whether by my session or any other) will use the cache?
    I've had a stab at this, but still, no joy:
    create or replace procedure testcache is
        emp employees%rowtype;
        begin
            select employees_cache.onerow(100) from dual into emp;
            dbms_output.put_line('Emp id: ' || emp.employee_id);
        end testcache;
    show errors
    HR@XE> @testcache.sql
    Warning: Procedure created with compilation errors.
    Errors for PROCEDURE TESTCACHE:
    LINE/COL ERROR
    4/9      PL/SQL: SQL Statement ignored
    4/54     PL/SQL: ORA-00933: SQL command not properly ended
    HR@XE>Have a feeling this should be really easy. Can anybody help?
    Many thanks in advance.
    Jason
    Edited by: 942375 on 08-Feb-2013 11:45

    >
    Ha, figured it out
    >
    Hopefully you also figured out that the example is just that: a technical example of how to use certain Oracle functionality. Unfortunately it is also an example of what you should NOT do in an actual application.
    That code isn't scaleable, uses expensive PGA memory, has no limit on the amount of memory that might be used and, contrary to your belief will result in EVERY SESSION HAVING ITS OWN CACHE of exactly the same data if the session even touches that package.
    Mr. Feuerstein is an expert in SQL and PL/SQL and his books cover virtually all of the functionality available. He also does an excellent job of providing examples to illustrate how that functionality can be combined and used. But the bulk of those examples are intended solely to illustrate the 'technical' aspects of the technology. They do not necessarily reflect best practices and they often do not address performance or other issues that need to be considered when actually using those techniques in a particular application. The examples show WHAT can be done but not necessarily WHEN or even IF a given technique should be used.
    It is up to the reader to learn the advantages and disadvantages of each technicalogical piece and determine when and how to use them.
    >
    Now, I have just done some googling, and it seems that what I am trying to do isn't possible. Apparently %ROWTYPE is PL/SQL, and not understood by SQL, so you can't call onerow() from sql. Correct?
    >
    That is correct. To be used by SQL you would need to create SQL types using the CREATE TYPE syntax. Currently that syntax does not support anything similar to %ROWTYPE.
    >
    So am I supposed to create a type of EMPLOYEES%ROWTYPE in a PL/SQL procedure, and the idea of this code, is that the first call to onerow() runs the initialiation code, which populates the cache, and all subsequent calls to onerow() (whether by my session or any other) will use the cache?
    >
    NO! That is a common misconception. Each session has its own set of package variables. Any session that touches that package will cause the entire EMPLOYEES table to be queried and stored in a new associative array specifically for that session.
    That duplicates the cache for each session using the package. So while there might be some marginal benefit for a single session to cache data like that the benefit usually disappears if multiple sessions are involved.
    The main use case that I am aware of where such caching has benefit is during ETL processing of staged data when the processing of each record is too complex to be done in SQL and the records need to be BULK loaded and the data manipulated in a loop. Then using an associative array as a lookup table to quickly get a small amount of data can be effective. And if the ETL procedure is being processed in parallel (meaning different sessions) then for a small lookup array the additional memory use is tolerable.
    Mitigating against that is the fact that:
    1. Such frequently used data that you might store in the array is likely to be cached by Oracle in the buffer cache anyway
    2. Newer versions of Oracle now have more than one cache
    3. The SQL query needed to get the data from the table will use a bind variable that eliminates repeated hard parsing.
    4. The cursor and the buffer caches ARE SHARED by multiple sessions globally.
    So the short story is that there would rarely be a use case where ARRAYs like that would be preferred over accessing the data from the table.

  • Can a loaded SWF call a function that lives in the parent?

    I'm building a pretty simple Flash site in AS3. There is a
    main movie (main.swf) that simply loads different swfs via buttons
    on a main nav bar. The user clicks on a MC in "main.swf" and a
    function is called, loadMyContent("section1.swf"), is called and it
    animates in nicely. Other buttons use the same function, loading
    section2.swf, section3.swf, etc.
    I've defined how "loadMyContent()" works in the the main
    movie's document class file. It's all working fine when I just need
    to load content from a user action from the buttons that live in
    "main.swf". I want to call that same "loadContent" function from
    within "section1.swf" and have "main.swf" run it's "loadContent"
    fuction, but I can't seem to figure out how to make a child call a
    function that lives in the parent.
    Is there any way of having my child do this?
    I have a suspicion I may have to define that "loadContent"
    somewhere else, but I'm a little stumped now. I'm not really
    familiar with design patterns yet, although I want to get an
    understanding of them sometime soon. Can anyone offer some help
    with my immediate need or suggest a route to a solution?
    Thanks.

    kglad,
    Thank you very much! That worked perfectly. My section1 FLA
    is now compiling it's SWF without complaint.
    In case someone else is following this, the exact code I
    ended up using to cast "this.parent.parent" as a MovieClip is:
    MovieClip(this.parent.parent).loadMyContent("section2.swf");
    The discussion I think kglad is referencing is
    this
    discussion. If that's not it, just let me know. Again, kglad,
    thank you!

  • How can I transfer a call to someone else?

    Hi all,
    how can I transfer a call (that I've answered and noticed that it's someome elses business) to someone else with Lumia 920 / 820 or 610? Is this basic function even possible?
    (It was with all the older phones).
    Please help 

    All the older Nokia phones you answer a call – you can put it on hold – call someone else, tell him/her that you are transferring a call – press  4 and hang up. Those two can continue the conversation together.
    That’s what I’m looking for.
    With Lumia I don’t want to be the 3rd wheel in the conversation... 
    I haven't found the way to end the call so that the others could continue (not even with conference call)

  • How can i make a pl/sql function for BLOB datatype

    hi..anyone here who is very familiar about BLOB datatype. i have a COLUMN_ID, COLUMN_A in a certain TABLE_1. COLUMN_A is blob datatype that contains almost 250,000rows
    SQL>select column_A from table_1 where column_id=1234567
    column_A
    00000001000000010000000606D4E833074B69EC06D4E91F074CO18406D50C58074C031E
    how can i make a user-defined function to compute and convert this blob datatype into decimal length value. this hex value are points in the map.. the function must contain
    1.get the length of a blob then
    2.convert blob to variable hexadecimal characters by parsing it into 8
    3.to_number function or other function used to convert haxadecimal characters to decimal numbers
    4.phythagorean formula to compute length between two points. this is the formula i think LENGTH =
    SQRT(power((coordinate_x-prev_coordinate_x),2)+power((coordinate_y-prev_y),2));
    after this when i type this
    SQL>select user_function(column_A) from table_1 where column_id=1234567
    user_functions(column_A)
    --output length will be in decimal value already
    the function will goes like this
    step1 is to get the blob length
    00000001000000010000000606D4E833074B69EC06D4E91F074CO18406D50C58074C031E
    step2 is parsing of data by eights
    00000001 =>1
    00000001 =>1
    00000006 =>6 (number of coordinates)
    06D4E833 => X1
    074B69EC => Y1
    06D4E91F => X2
    074CO184 => Y2
    06D50C58 => X3
    074C031E => Y3
    step3 to_number function used to convert hex char to decimal
    step4 compute by phytagorean (NOTE ! when computing length the third parsed eight will tell how many coordinates are there..the number of coordinates is ranging from 2 up to E..above example shows 6 coordinates so it means
    LENGTH1 =
    SQRT(power((X2-X1),2)+power((Y2-Y1),2));
    LENGTH2=
    SQRT(power((X3-X2),2)+power((Y3-Y2),2));
    TOTAL LENGTH=LENGTH1 + LENGTH2
    thanks

    its my first time to use that.There's got to be a first tiem for anything. Be brave.
    btw if theres more easy suggestion pls feel free..Well of course the easiest solution would be if the calling program passed in the parameters as separate arguments instead of glomming them together in a string that has to be parsed. This sort of kluj really ought not to have survived into C21.
    Cheers, APC

  • Calling a function in another class that is not the App delegate nor a sngl

    Hi all-
    OK- I have searched and read and searched, however I cannot figure out an easy way to call a function in another class if that class is not the app delegate (I have that down) nor a singleton (done that also- but too much code)
    If you use the method Rick posted:
    MainView *myMainView = [[MainView alloc] init];
    [MyMainView goTell];
    That works, however myMainView is a second instance of the class MainView- I want to talk to the instance/Class already instantiated.
    Is there a way to do that without making the class a singleton?
    Thanks!

    I had some trouble wrapping my head around this stuff at first too.
    I've gotten pretty good at letting my objects communicate with one another, however I don't think my method is the most efficient or organized way but I'll try to explain the basic idea.
    When you want a class to be able to talk to another class that's initialized elsewhere, the class your making should just have a pointer in it to the class you want to communicate with. Then at some point (during your init function for example) you should set the pointer to the class you're trying to message.
    for example in the app-delegate assume you have an instance of a MainView class
    and the app-delegate also makes an instance of a class called WorkClass
    If you want WorkClass to know about MainView just give it a pointer of MainView and set it when it's instantiated.
    So WorkClass might be defined something like this
    //WorkClass.h
    @import "MainView.h"
    @interface WorkClass : NSObject
    MainView *myPointerToTheMainView;
    @property (retain) myPointerToTheMainView;
    -(void)tellMainViewHello;
    @end
    //WorkClass.m
    @import "WorkClass.h"
    @implementation WorkClass
    @synthesize myPointerToTheMainView;//this makes getter and setter functions for
    //the pointer and allows us to use the dot
    //syntax to refrence it.
    -(void)tellMainViewHello
    [myPointerToTheMainView hello]; //sends a message to the main view
    //assume the class MainView has defined a
    //method -(void)hello
    @end
    now somewhere in the app delegate you would make the WorkClass instance and pass it a reference to the MainView class so that WorkClass would be able to call it's say hello method, and have the method go where you want (to the single instance of MainView owned by the app-delegate)
    ex:
    //somewhere in app-delegate's initialization
    //assume MainView *theMainView exists and is instantiated.
    WorkClass *myWorkClass = [[WorkClass alloc] init];
    myWorkClass.myPointerToTheMainView = theMainView; //now myWorkClass can speak with
    // the main view through it's
    // reference to it
    I hope that gets the basic idea across.
    I'm pretty new to Obj-c myself so if I made any mistakes or if anyone has a better way to go about this please feel free to add
    Message was edited by: kodafox

  • How can and where i use the function "HTMLDB_UTIL.CLEAR_PAGE_CACHE "

    how can and where i use the function "HTMLDB_UTIL.CLEAR_PAGE_CACHE " ?
    where is the place to put this function?

    i have notice that sometime, during visual a report of a table, order by data insert desc, some record are not displayed on some client.
    Only whe we clear the cache of internet explorer than this record can view.
    I have an idea that a clear page when i call the report may be solve the problem.
    Thank's.
    ------------------------

  • How can i use talking caller id without jailbreak and those wacky apps

    how can i use talking caller id without jailbreak and those wacky apps

    Talking caller ID is not a feature of the iPhone. If by "wacky apps" you mean the ones that make custom ring tones for each contact from their name, that's your best bet.

  • Can EE Customer service call me on my phone? I can not call to UK from abroad

    URGENT Can EE Customer service call me on my phone?  I can not call to UK from abroad

    Hi ,
    Very sorry this is a public forum no calls can be made.
    How can I help with your query?
    Thanks.

  • How can i watch native code for hashCode() in Object class?

    How can i watch native code for hashCode() in Object class?

    Those are two different requirements. You still haven't told us why you want the first one.
    The second one is called JNI - Java Native Interface. There is a forum here, and a large amount of documentation, and a book about it.

  • How can i record a call on my iphone 3gs.?

    how can i record a call on my iphone 3gs

    Not supported by Apple, and most apps that claim to provide this functionality don't work on a non-jailbroken iPhone.

  • How can I make a call from iPad

    How can I make a call from IPad

    Oh, you have to get the iPhone app.
    Seriously, though .... you are aware that it's not a telephone, right? Any calls you make will be using VOIP and any of the apps and/or services (Skype, Google Talk, etc., etc.) which support that. Some of those are US-only, all have various restrictions and cost structures.

  • How can I  custom my date  in OBIEE.

    How can I custom my date in OBIEE.I want to see date in my user friendly format for Date Format MM/DD/YYYY to filter with
    leading zero(number) eg (01.21.2008) and not M/D/YYYY (1.21.2008) that i am seeing.I would appreciate it if you could give me a step by step process on how to do it in RPD.I know how to change the data format in my column propeties since i have more that 5000 columns that need changed.I am looking for a localised area
    that can take care of business.
    Thanks

    Edit the following parameters in OracleBI\web\config\localedefinitions.xml
    - Search for the locale that you want to customize by looking for the tag *<localeDefinition name="en">*
    - Customize the following tags as you require
    <property name="dateShortFormat">MM/DD/YYYY</property>
    <property name="dateLongFormat">dddd, MMMM dd, yyyy</property>
    - Restart the presentation server

  • How can i erase an account with relationship with some class of tax

    how can i erase an account with relationship with some class of tax

    Hi Enrique,
    I am not sure what you mean by this, can you please explain in more detail? You cannot erase accounts that already have transactions posted to it.
    Hope it helps,
    Adele

Maybe you are looking for

  • CUCM Upgrade to 9.1.2.13900-10

    Dear Team, I am planning to upgrade CUCM  from 9.1.2.10000-28   to  UCSInstall_UCOS_9.1.2.13900-10.sgn . Please share with me the upgradation steps and documents  ? Thanks

  • How to pass the internal table defined in program to ALV

    Hi Friends, I have a doubt regaring the ALV's, How can we pass the internal table defined in the program to ALV by not filling the attribute (I_STRUCTURE_NAME) in the REUSE_ALV_LIST_DISPLAY. I have tried many ways but unable to pass the structure of

  • Not getting correct data for newly added field in 0FI_AR_4

    Hi to all, I have added SPART field from VBRK table into 0FI_AR_4 datasource . Based on join BSID-VBELN = VBRK-VBELN to get SPART from VBRK table. but i found that some VBELN are not maintained in VBRK table, But are Present in BSID table, so i am no

  • Adobe Flash Player is not working

    I have installed adobe flash player on my Imac but for some reason I cannot get anything to open that requires flash player

  • Service tax configuration

    HI How to configuration service tax in the arline industry.Because in the arline no any excise duty is there.when i m trying to run the service tax report this i have geeting the error depot is not maintain. i know in excixe group plant is not assign