Anybody can help me to identify the object???

Here I have two object, one is the instance of the parent class Class1, another is the instance of child class Class2, how to identify them in my program? Thanks in advance.
Here I attach the logic in my program:
public void myfunction(Object obj)
if (obj instanceof Class1)
process1();
if (obj instanceof Class2)
process2();
when I invoke myfunction with parameter obj which is the instance of Class2, the process1 was run, and process2 was run too, why it happens? how to identify them?

That should have been
public void myfunction(Object obj)
if (obj instanceof Class1)
process1();
else if (obj instanceof Class2)
process2();
else
System.err.println("Unexpected object type: "+obj);
Since Class1 is the superclass of Class2, every instance of Class2 is an instance of Class1, and process2 will never be executed in the above code.
You should probably use a callback method. E.g:
public class MyClass {
    public final void process1() {
        System.out.println("process1 called");
    public final void process2() {
        System.out.println("process2 called");
    public void mymethod(Processable p) {
        p.process(this);
    public static void main(String args[]) {
        MyClass instance = new MyClass();
        instance.mymethod(new Class1());
        instance.mymethod(new Class2());
interface Processable {
    void process(MyClass processor);
class Class1 implements Processable {
    public void process(MyClass processor) {
        processor.process1();
class Class2 extends Class1 {
    public void process(MyClass processor) {
        processor.process2();
Note that the mymethod method does not need to be updated every time you add a new subclass - you just need to write a process method for the new subclass.

Similar Messages

  • Anybody can help me understand if the Ipads becomes ready to be used in all world regions with 3G and or 4G infrastructure? I mean, are all of them released or when I buy one in the US to be used in Argentina I need to ask for a released one, less cheaper

    anybody can help me understand if the Ipads becomes ready to be used in all world regions with 3G and or 4G infrastructure? I mean, are all of them released or when I buy one in the US to be used in Argentina I need to ask for a released one, with add costs?

    There are two versions of the current iPad, the WiFi only (which will work anywhere in the world, but only connect to WiFi networks) and the 3G/4G model. The latter will connect to 3G networks worldwide, as I understand it, but the only 4G networks it can connect to are in the US and Canada.

  • My iphone 4's backlight turns off ocassionally.,some say update it and it will be ok..,anybody can help me?

    my iphone 4's backlight turns off ocassionally.,some say update it and it will be ok..,anybody can help me?

    yes the phone is already on..,autolock is set to 1 min..,what i mean is that whenever im using my iphone the backlight turns off and i got a black sceen but i can  see the icons on my iphone if i put it on a bright light..,even if i press the wake up botton the backlight just lit at little and it turns off again,,,and after about 30 mins on sleep mode and press the wake up button it will function as a normal again,few minutes after backlights turns off again..thanks!

  • The speaker of my brand new mac book pro are not working and I cannot plug in the earphones, the hole looks smaller than the pin or with an obstruction. anybody can help? thanks

    the speakers of my brand new mac book pro are not working and I cannot plug in the earphones, the hole looks smaller than the pin or with an obstruction. anybody can help? thanks

    Hi talero,
    Contact AppleCare or bring it into an Apple Store or AASP.

  • HT1212 i have a iphone 8g and the lock button doesnt work and i forgot my password and i was wondering if anybody can help me??

    i have a iphone 8g and the lock button doesnt work and i forgot my password and i was wondering if anybody can help me??

    You will need to restore your iPhone, take a look at this link, http://support.apple.com/kb/HT1212

  • Anybody can help me? I'm trying to start my computer and it shows this question mark. Then i restart it holding the option key and it shows this padlock with a password field. What should password should i put?

    Anybody can help me? I'm trying to start my computer and it shows this question mark. Then i restart it holding the option key and it shows a padlock with a password field. What password should i put? I would appreciate any help

    Contact Apple, or if you bought the computer secondhand, the previous owner.
    (118258)

  • I saw a message "cannot get mail. The connection to the server failed". Anybody can help pls?

    I saw a message "cannot get mail. The connection to the server failed". Anybody can help pls? I did try to delete the account and add back. Also tried to reset/ reboot the iPad but still effortless.

    Hi all, I finally solved the issue. Here I wish to share with you all. First, I delete my hotmail account from mail account. Secondly I reboot my ipad2 with holding sleep and home button at once untill the apple logo is appeared. Then I add back the hotmail account. Done. Hope it helps. Thank you.

  • Hello, I can't open the FluidTunes. Anybody can help me?

    Hello, I can't open the FluidTunes. Anybody can help me?

    You didn't give any information other than you have have some kind of iMac. You should probably contact the maker of the software http://majicjungle.com/about.html and click on the email for support.

  • I cannot download or updates any apps after upgrading the newest ios .. it show offers In-Apps Purchase... anybody can help me ?

    i cannot download or updates any apps after upgrading the newest ios .. it show offers In-Apps Purchase... anybody can help me ?

    This is happening to me too. I'm looking for anyway to fix this its getting very annoying not being able to update apps.

  • I suspect a spy app on my iphone 4 that somebody watching my calls/ voice conversation. Can somebody help me to identify the app and how to remove it?

    I suspect a spy app on my iphone 4 that somebody watching my calls/ voice conversation. Can somebody help me to identify the app and how to remove it?

    No spy app can be installed on iphone which is not jailbroken.
    For example iKeyMonitor iPhone spy can not be installed without jailbroken.
    http://ikeymonitor.com

  • HT201066 I have problem with recently with playing DVDs on my iMac. the problem only with DVDs, please anybody can help me solve this problem?

    I have problem with recently with playing DVDs on my iMac. the problem only with DVDs, please anybody can help me solve this problem?

    Get a lens cleaner disc. One with brushes and try that. CDs and DVDs use different lenses, so since CDs load and play, I strongly suspect a dirty lens.

  • How can I cancel my subscripction before 30 days are passed? I don't find any telephone number or addresse where I can do the cancel. Anybody can help me? thanks

    How can I cancel my subscripction before 30 days are passed? I don't find any telephone number or addresse where I can do the cancel. Anybody can help me? thanks

    Cancel http://helpx.adobe.com/x-productkb/policy-pricing/return-cancel-or-change-order.html
    -or by telephone http://helpx.adobe.com/x-productkb/global/phone-support-orders.html

  • I have purchased the app geowalk and garaband from the ipad itself and found it was very slow to get it installed. Then I used a pc (not mac) to download the app and found that I cant install to the ipad. It said error... anybody can help?

    Help! I have purchased the app geowalk and garaband from the ipad itself but found the files were too big and the process is too slow. I later use non mac pc to install the 2 apps but I couldnt tranfer to the ipad. It always said error. anyone can help?
    Thanks

    WHat does the error say?  Is there an error code?

  • Help needed in Identifying dependent objects

    Hi all,
    Basically I need to identify the object related to Integration which is not there in one of our software product under development as compare to other(existing) already developed so that we can apply them in the product being developed.
    I need to find these below from few of the packages given to me
         dependent packages/functions to read and update data
    1)     Tables
    2)     Packages
    3)     Triggers
    4)     Views
    5) Jobs
    I would request you to help me in carrying out this faster, I have plsql Developer tool, how to start with so that i m not mess up with and complete it faster.
    Regards,
    Asif.

    Thankx Pierre Forstmann.
    Dear All,
    Can any one help me in identifying all dependent objects for one object.
    Will this works for me I found from the above link provided,
    as for the time being I do not have the dba priviliges...
    If I am able to get the dba prviliges will this code works for me to get the
    required information....
    Regards,
    AAK.
    SQL>
    create or replace type myScalarType as object
    ( lvl number,
    rname varchar2(30),
    rowner varchar2(30),
    rtype varchar2(30)
    Type created.
    SQL> create or replace type myTableType as table of
    myScalarType
    Type created.
    SQL>
    SQL> create or replace
    function depends( p_name in varchar2,
    p_type in varchar2,
    p_owner in varchar2 default USER,
    p_lvl in number default 1 ) return myTableType
    AUTHID CURRENT_USER
    as
    l_data myTableType := myTableType();
    procedure recurse( p_name in varchar2,
    p_type in varchar2,
    p_owner in varchar2,
    p_lvl in number )
    is
    begin
    if ( l_data.count > 1000 )
    then
    raise_application_error( -20001, 'probable connect by loop,
    aborting' );
    end if;
    for x in ( select /*+ first_rows */ referenced_name,
    referenced_owner,
    referenced_type
    from dba_dependencies
    where owner = p_owner
    and type = p_type
    and name = p_name )
    loop
    l_data.extend;
    l_data(l_data.count) :=
    myScalarType( p_lvl, x.referenced_name,
    x.referenced_owner, x.referenced_type );
    recurse( x.referenced_name, x.referenced_type,
    x.referenced_owner, p_lvl+1);
    end loop;
    end;
    begin
    l_data.extend;
    l_data(l_data.count) := myScalarType( 1, p_name, p_owner, p_type );
    recurse( p_name, p_type, p_owner, 2 );
    return l_data;
    end;
    Function created.
    SQL>
    SQL> set timing on
    SQL>
    SQL> select * from table(
    cast(depends('DBA_VIEWS','VIEW','SYS') as myTableType ) );
    ---select * from table(cast('USER_VIEWS') as myTableType ) );
    LVL     RNAME          ROWNER          RTYPE
    1     DBA_VIEWS     SYS               VIEW
    2     TYPED_VIEW$ SYS               TABLE
    2     USER$          SYS               TABLE
    2     VIEW$          SYS               TABLE
    2     OBJ$          SYS               TABLE
    2     SUPEROBJ$ SYS               TABLE
    2     STANDARD SYS               PACKAGE
    7 rows selected.
    Elapsed: 00:00:00.42
    SQL>
    SQL>
    SQL> drop table t;
    Table dropped.
    Elapsed: 00:00:00.13
    SQL> create table t ( x int );
    Table created.
    Elapsed: 00:00:00.03
    SQL> create or replace view v1 as select * from t;
    View created.
    Elapsed: 00:00:00.06
    SQL> create or replace view v2 as select t.x xx, v1.x yy from
    v1, t;
    View created.
    Elapsed: 00:00:00.06
    SQL> create or replace view v3 as select v2.*, t.x xxx, v1.x
    yyy from v2, v1, t;
    View created.
    Elapsed: 00:00:00.07
    SQL>
    SQL>
    SQL> select lpad(' ',lvl*2,' ') || rowner || '.' || rname ||
    '(' || rtype || ')' hierarchy
    2 from table( cast(depends('V3','VIEW') as myTableType ) );
    HIERARCHY
    OPS$TKYTE.V3(VIEW)
    OPS$TKYTE.T(TABLE)
    OPS$TKYTE.V1(VIEW)
    OPS$TKYTE.T(TABLE)
    OPS$TKYTE.V2(VIEW)
    OPS$TKYTE.T(TABLE)
    OPS$TKYTE.V1(VIEW)
    OPS$TKYTE.T(TABLE)
    8 rows selected.
    Message was edited by:
    460425

  • Anybody can help with this SQL?

    The table is simple, only 2 columns:
    create table personpay(
    id integer primary key,
    pay number(8,2) not null);
    So the original talbe looks like this:
    ID PAY
    1 800
    2 400
    3 1200
    4 500
    5 600
    6 1900
    The requirement is to use one single query(no pl/sql) to show something lile the following, in other words, for each ID, the pay is the sum of all before itself and itself. So the query result looks like this:
    ID PAY
    1 800
    2 1200
    3 2400
    4 2900
    5 3500
    6 5400
    Again, just use one sql. No pl/sql. Anybody can help with this? I really appreciate that.
    thanks,

    Eh, people are so "analytically minded" that can't even notice a simple join?
    Counting Ordered Rows
    Let’s start with a basic counting problem. Suppose we are given a list of integers, for example:
    x
    2
    3
    4
    6
    9
    and want to enumerate all of them sequentially like this:
    x      #
    2      1
    3      2
    4      3
    6      4
    9      5
    Enumerating rows in the increasing order is the same as counting how many rows precede a given row.
    SQL enjoys success unparalleled by any rival query language. Not the last reason for such popularity might be credited to its proximity to English . Let examine the informal idea
    Enumerating rows in increasing order is counting how many rows precede a given row.
    carefully. Perhaps the most important is that we referred to the rows in the source table twice: first, to a given row, second, to a preceding row. Therefore, we need to join our number list with itself (fig 1.1).
    Cartesian Product
    Surprisingly, not many basic SQL tutorials, which are so abundant on the web today, mention Cartesian product. Cartesian product is a join operator with no join condition
    select A.*, B.* from A, B
    Figure 1.1: Cartesian product of the set A = {2,3,4,6,9} by itself. Counting all the elements x that are no greater than y produces the sequence number of y in the set A.
    Carrying over this idea into formal SQL query is straightforward. As it is our first query in this book, let’s do it step by step. The Cartesian product itself is
    select t.x x, tt.x y
    from T t, T tt
    Next, the triangle area below the main diagonal is
    select t.x x, tt.x y
    from T t, T tt
    where tt.x <= t.x
    Finally, we need only one column – t.x – which we group the previous result by and count
    select t.x, count(*) seqNum
    from T t, T tt
    where tt.x <= t.x
    group by t.x
    What if we modify the problem slightly and ask for a list of pairs where each number is coupled with its predecessor?
    x      predecessor
    2      
    3      2
    4      3
    6      4
    9      6
    Let me provide a typical mathematician’s answer, first -- it is remarkable in a certain way. Given that we already know how to number list elements successively, it might be tempted to reduce the current problem to the previous one:
    Enumerate all the numbers in the increasing order and match each sequence number seq# with predecessor seq#-1. Next!
    This attitude is, undoubtedly, the most economical way of thinking, although not necessarily producing the most efficient SQL. Therefore, let’s revisit our original approach, as illustrated on fig 1.2.
    Figure 1.2: Cartesian product of the set A = {2,3,4,6,9} by itself. The predecessor of y is the maximal number in a set of x that are less than y. There is no predecessor for y = 2.
    This translates into the following SQL query
    select t.x, max(tt.x) predecessor
    from T t, T tt
    where tt.x < t.x
    group by t.x
    Both solutions are expressed in standard SQL leveraging join and grouping with aggregation. Alternatively, instead of joining and grouping why don’t we calculate the count or max just in place as a correlated scalar subquery:
    select t.x,
    (select count(*) from T tt where tt.x <= t.x) seq#
    from T t
    group by t.x
    The subquery always returns a single value; this is why it is called scalar. The tt.x <= t.x predicate connects it to the outer query; this is why it is called correlated. Arguably, leveraging correlated scalar subqueries is one the most intuitive techniques to write SQL queries.
    How about counting rows that are not necessarily distinct? This is where our method breaks. It is challenging to distinguish duplicate rows by purely logical means, so that various less “pure” counting methods were devised. They all, however, require extending the SQL syntactically, which was the beginning of slipping along the ever increasing language complexity slope.
    Here is how analytic SQL extension counts rows
    select x, rank() over(order by x) seq# from T; -- first problem
    select x, lag() over(order by x) seq# from T; -- second problem
    Many people suggest that it’s not only more efficient, but more intuitive. The idea that “analytics rocks” can be challenged in many ways. The syntactic clarity has its cost: SQL programmer has to remember (or, at least, lookup) the list of analytic functions. The performance argument is not evident, since non-analytical queries are simpler construction from optimizer perspective. A shorter list of physical execution operators implies fewer query transformation rules, and less dramatic combinatorial explosion of the optimizer search space.
    It might even be argued that the syntax could be better. The partition by and order by clauses have similar functionality to the group by and order by clauses in the main query block. Yet one name was reused, and the other had been chosen to have a new name. Unlike other scalar expressions, which can be placed anywhere in SQL query where scalar values are accepted, the analytics clause lives in the scope of the select clause only. I have never been able to suppress an impression that analytic extension could be designed in more natural way.

Maybe you are looking for

  • Weird internet problem / ssl connection error, site loads in safari not in firefox or other way around

    I really can't figure out this problem. Search the internet tried all kinds of things, nothing help so far. I have a Macbook Pro (Lion originally installed) running on Mavericks (all latest updates). SSD installed and the DVD tray is replaced by the

  • Info path 2010 web service(getuserprofilebyname) not able connect in the browser mode

    Hi all, I have published the info path which will reterieve the current user using the getuserprofilebyname service. The service gets the current user when the form is opened in the info path filler after publishing. It shows the below error when I t

  • Final Cut Pro X won't record voiceover

    I was using FCPX 10.1.3 when this problem appeared, now I'm on 10.1.4 and it wasn't fixed. Here's the summary: when I open a "Record Voiceover" window everything works fine, I can select different input devices, set up event, I can even hear myself w

  • Connecting to VCR to record audio

    I was wondering if it was possible to record audio from my VCR onto my Mac. I have a recording software already, but am wondering what kind of cord I will need in order to accomplish this. Many thanks in advance.

  • Send eMail per FUBA aus SAP

    Hello, I would like to send a mail in csv to User with internet. I dont have errors but I did not get a email. Commit_work is X.  In TA SCOT is no entry. Can somebody help? Thanks a lot. My code: FUNCTION z_test_mail2. ""Lokale Schnittstelle: Testpro