Question: equals() for objects, not necessarily strings

My book goes over the equals(String str) method, but it does not cover other objects. For example, in the code below the equals method returns false by printing, "The objects are not equal" even though both objects contain the same numbers. I looked at the API, but it was confusing. I'm not that far along yet. Any answers to why the equals() returns a false below?
public class Exp
     public static void main(String[] args)
          Exp2 e = new Exp2(6, 8);
          Exp2 e1 = new Exp2(6, 8);
          if(e.equals(e1))
               System.out.println("Objects are equal.");
          else
               System.out.println("Objects are not equal.");
               System.out.println("");
}

paulcw wrote:
If you're the author of the Exp2 class, and you think that two objects of Exp2 that have been initialized with equal values should be equal (seems reasonable), then you'd define an equals method in Exp2 to express that.Exactly, just like the String class has code to explicitly compare the two String objects' characters.
The default equals() doesn't automagically compare objects' contents. I just uses == to see if the two references are pointing to the same object. If you want other behavior, you have to provide it, like String does.

Similar Messages

  • Managing multiple collision detection between objects(not necessarily circles)

    Hi.
    I´d like to know if there´s any good tutorial, or if somebody knows, a way, to manage a multiple collision detection with pixel level detection, for objects, not necessarily circles, irregular objects.
    Any help?

    Yes, and what about the speeds of each object?
    I was thinking something like this:
    var  _currentObj1SpeedX = obj1.speedX
    var  _currentObj1SpeedY = obj1.speedY
    obj1.speedX = obj1.speedX - obj2.speedX
    obj1.speedY = obj1.speedY - obj2.speedY
    obj2.speedX = obj2.speedX -  _currentObj1SpeedX
    obj2.speedY = obj2.speedY -  _currentObj1SpeedY
    Is it right?

  • PO create error u2018Number range ZB for object not definedu2019

    Dear all
             I have a error in ME21N to create PO,When I click save button,then occurs a error u2018Number range ZB for object not definedu2019.
    I define a PO types:u2019Z506u2019 and assigned to the Number Range u20185Hu2019.The u20185Hu2019 is from 5070000001 to 5079999999 not ext.
    The u2018ZBu2019 number range is defined PR,not PO.So I donu2019t know where does define wrong?
    Please help me!
    Thanks
    Sun

    Hi
    Please check if you have Defined the Number ranges for Document type ZNB  in
    SPRO-> Materials Management-> Purchasing-> Purchase Requisition-> Define Number Ranges
    The reason the error is Coming like that is, in the Customizing of PO Doucment types in
    SPRO-> Materials Management-> Purchasing-> Purchase Order-> Define Document Types-> Link purchase requisition - document type
    here you have maintained the Link for the PR & The PO.
    Thanks & Regards
    Kishore

  • Bevel and emboss for object, not text

    Is there a way to apply a bevel to a shape that I created in Photoshop and "placed" into Illustrator? I know I can add the bevel in Photoshop, but I'm wondering if there's a way to do it in Illustrator as well.
    Thanks!

    These methods work for object, not just text.
    http://forums.adobe.com/thread/480665

  • Services for Object Not Working in Portal

    Hi Experts!!
    We have created an iView for PR01 standard t-code. Now when we are testing it, we found that the button for Services for Object is being displayed on the page. But when trying to Create Attachment, it's not going further. Instead it's showing some message as 'Please wait. You will be forwarded automatically.This page had to be included for technical reasons.'
    But nothing is happening later. It should provide me to enter the file path.
    Can anybody suggest how I can get that? Your help is highly appreciable.

    I had a similar problem using a different Javascript menu. If you take a look at the HTML generated by the portal and break it down into smaller sections you may find the HTML that is causing your Javascript not to load. It's a tedious task, but not all Javascript is the same. Note, if your javascript is using or manipulating the <div> tag. It must be relative positioned to an image or div or you may run into the problem of the javscript loading and displaying relative to the browser as opposed to your portlets.
    Laith E.H.

  • Button for services for object not showing for FB03

    Hi,
    I have a created a Zcopy of transaction FB03.
    But the button for services of object which contains attachment list and other features is not showing up in my Z trasaction.
    Does anyone know the reason or the functionality behind this button.

    Create a replica Z prg of the std prg SAPMF05L and assign a Z tcode to it.

  • CSS Question: IE7 for Windows Not Behaving

    Hi all,
    I hope there is a CSS buddy out there today.  I have a page that I've built using only CSS (New to doing this) and the page works in Safari, Firefox on both Mac and PC, but IE7 on Windows is rendering the logo/header/navigation wrong.
    Maybe there is a better way to do this.  I'm wanting the logo floated to the left so it sits over the borders on the header, navigation & main content box.  I thought I was all clever when it worked on my Mac.  It seems like it's a simple fix, but I just can't get anything to work. IE7 seems to not be floated above and is pushing the header and navigation to it's right.  So the header and the nav are wrapping around the logo instead of sitting under.
    Thanks for your help in advance!
    Tim

    GarryCT wrote:
    IE does not implement floating correctly, although it usually doesn't cause problems.  They misinterpret the w3c spec and float the element rather than the content.  You could see this if you floated two adjacent divs with different background colors in different browsers.  This may be part of the issue.
    Can you post a reference for this and an example, please?  I am unaware of such an issue as you describe.
    I would recommend making the header section a wrapper containing your background.  If you need to, you can position your background image relative to the right.
    I believe that's already how it has been done.
    To get around the IE issue, you may need to play around with relative or absolute positioning (relative to the header, not the body) to get the alignment you want.
    Alternatively, you could create the header with the background image as indicated above, then within that, float the navigation element to the right (pushing it down by setting the top margin or padding) then follow them with the image tags without the div containers.  They are inline so they will 'float' naturally.  Set margins on the images to get your spacing between the images.
    Hope that helps.
    I don't see any help there.  Sorry.

  • Keeps finding a "Object" not the real type.. I am really lost.. :D

    The calls to other objects work fine, I have testing all of them.. but! when I compile I get a error about finding a "object" type and not a String type at
    for(String blackStone : blackUnits.keySet())
                   if( getSetLib(blackStone) == 0 ) { removeSet.add(blackStone); }
             }   this is the whole class
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.HashSet;
    import java.util.Set;
    public class Stat
        private Token[][] board;
        private int bSize;
        private HashMap<String, HashSet> unitsWhite;
        private HashMap<String, HashSet> unitsBlack;
        double last;
        public Stat(Token[][] goBoard, int size)
            board = goBoard;
            bSize = size;
            unitsWhite = new HashMap< String , HashSet>();
            unitsBlack = new HashMap< String , HashSet>();
            last = bSize -1;
         * Delimiter is /
        public HashSet getLib(int x , int y)
            HashSet liberties = new HashSet<String>();
            //error catch
            if(board[x][y] == null){return liberties;}
            int tempX = x;
            int tempY = y;
            //error catch for out of rage if size ect..
            for(int i = 0 , liby = y ,libx = x ; i <= 3; i++)
                if(i == 0){libx = -1; liby = 0;}
                if(i == 1){libx = 0; liby = -1;}
                if(i == 2){libx = 1; liby = 0;}
                if(i == 3){libx = 0; liby = 1;}
                tempX = x+libx;
                tempY = y+liby;
                if(tempX >= 0 || tempY >= 0)
                    if( tempX <= last || tempY <= last )   
                         if( (tempX < 0 || tempY < 0) || ( tempX >= last || tempY >= last ) )
                           tempX = 0;
                           tempY = 0;
                         else
                            if( board[tempX][tempY] == null) { liberties.add(tempX+"/"+tempY); }
            return liberties;  
        public void getTer()
        public void checkForCaptured()
            Token black = null;
            Token white = null;
            HashMap blackUnits;
            HashMap whiteUnits; 
            HashSet removeSet ;
            removeSet = new HashSet<String>();
            //look for a Token on the board and if you find one look for any dead  Tokens
            //looks for a Token
            for(int x=0; x < bSize;x++)
              { for(int y=0 ; y < bSize   ;y++)
               { if(board[x][y] != null)
                   if (black == null)if( board[x][y].getColor().equals("black") ) black =  board[y][x];
                   if (white == null)if( board[x][y].getColor().equals("white") ) white =  board[y][x];
            System.out.println("this is black tokens color" +black.getColor());
            //looks for a dead unit
            if(black != null)
             { blackUnits = black.getUnits();
               System.out.println("black :" +blackUnits.keySet().size() ) ;
               for(String blackStone : blackUnits.keySet())
                   if( getSetLib(blackStone) == 0 ) { removeSet.add(blackStone); }
            if(white != null)
            { whiteUnits = white.getUnits();
                System.out.println(" white: "+whiteUnits.keySet().size() );
              for( String whiteStone : whiteUnits.keySet() )
               { if( getSetLib(whiteStone) == 0 ) { removeSet.add(whiteStone); } }
            board.removeUnitsSet(removeSet);    
         public int getSetLib(HashSet Units)
             return 0;
    }someone point me in the correct direction PLZ! I don't mind RTFM if you give me a FM and page/line to look at.
    THANKS!
    Message was edited by:
    monji112000

    The compiler doesn't know that you're only putting Strings in as keys. HashMap takes references to Object as keys and hence returns references to Object in keySet(). Note, however, that the object itself is still what you put in there. But the compiler only has the declared return type of the method to look at.
    // pre 1.5
    for (Iterator iter = set.iterator(); iter.hasNext();) {
        String key = (String)iter.next(); // cast Object to String. Only works if you actually put a String in
        // do stuff with key
    // 1.5, if you don't use generics
    for (Object obj : set) {
        String key = (String)obj;
        // do stuff with key
    // 1.5, with generics
    Set<String> set = ...;
    for (String key : set) {
        // do stuff with key
    }Since you have a Map, you'll have Map<String, SomeValueType>.
    http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html
    http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf

  • Query Operator "IS" is not working good for object type "String"

    Hi,
    I have a problem with advanced search. When the object type is String, and I want to search directly value (for exemple 'a') i have returned all value starts with 'a', even though I set Query Operator to "IS"
    When I use Query operator "setByUser", and then set property to "IS", query behaviour is correct.
    Behaviour example for operator "IS":
    values: a, ab, abc
    searching: 'a' --> expected results: a results: a, ab, abc
    Any sugestions??
    Sorry for my English
    Regards,
    Wojciech Mularczyk

    Syed,
    Only under advanced search. The operator used for quick search is defined through two properties in JhsAdvancedSearch bean class:
    private String defaultStringOperator = "startsWith";
    private String defaultNonStringOperator = "is";
    So, if you have a String attribute which holds numbers and you want to apply the "is" operator to this attribute, you can change the default value of "defaultStringOperator" by creating a custom template for searchBean.vm, and add the following property:
    <managed-property>
    <property-name>defaultStringOperator </property-name>
    <value>is</value>
    </managed-property>
    Note hat you can already apply this technique in the current release.
    Steven Davelaar,
    JHeadstart Team.

  • Services for Objects Attachement List Display Note not Viewable

    Hi Experts!
    Good day! I'm trying to display a note in FK03 (related to Services for Objects - Attachment List) and I only see white screen pop up window. No message and text information. When I tried to use another PC I can successfully view it.
    Is there's a plugin that I may need to install?
    Your help will be greatly appreciated.

    Hi Marty
    It is my understanding that the IXOS licensing is based on users retrieving of documents not necessarily the viewer so the licensing implications of having non-IXOS viewers accessing documents using the generic archivelink viewer is still likely to result in licensing implications if an audit is conducted at any stage.
    The transaction for specifying the viewer is the OAA3 and OAG4.
    Regards,
    Athol

  • Services for Object (GOS) Attachement List not showing after attachment

    Hi All,
    I have created a new entry for the Generic Object Service List and this links to a copy of the CL_GOS_SRV_ATTACHMENT_CREATE class (Create attachment) with some additional logic. However, after attaching a file, the "Attachment List" does not become available until after I re-enter the transaction. The attachment list is showing the correct attachments.
    After some (understatement...) investigation, I found that even if I try and link the new service to a unchanged copy of the CL_GOS_SRV_ATTACHMENT_CREATE service in SGOSATTR, it is not working. It is attaching fine, but the "Attachment List" entry in the Services for Object Menu is still greyed out. If I attach the original class CL_GOS_SRV_ATTACHMENT_CREATE to the newly created entry it works fine. e.g. straight after I attach a file to the transaction, the menu entry becomes available.
    I can't find where the re-draw of the GOS menu happens and hence can not determine what is going wrong. Does anybody know if this is part of the Kernel or is this actually done in ABAP ?
    Am I missing something ? Debugging including system debugging for two days now and can't find it... very frustrating.
    Any help would be appreciated.
    Thanks,
    Wouter.

    Hi Wouter,
    I had originally posted to ask if you had resolved this since I was facing the same issue, but then deleted my post when I was able to get it working. Sorry, I didn't mean to initiate a flurry of activity in such an old thread.
    My scenario is I created a new GOS service entry in table SGOSATTR using transaction SGOSM. My new service uploads attachments to an external document management system via a call to a RESTful web service. The class I use in the SGOSM entry is a custom subclass of CL_GOS_SRV_URL_CREATE.
    I resolved this issue by taking a look at what CL_GOS_SRV_URL_CREATE does in its EXECUTE method. The key bits to refresh the GOS Attachment List with the new attachment are...
    raise event commit_required. " if SGOSM has the commit flag checked
    raise event service_succeeded
           exporting eo_service = me.
    These events tell any subscribers to go do their thing-- which in this case includes a refresh of the GOS Attachment List. So in the EXECUTE method of my custom subclass, after I call function BINARY_RELATION_CREATE, I raise these events...
    CALL FUNCTION 'BINARY_RELATION_CREATE'
       EXPORTING
           obj_rolea     = gs_object
           obj_roleb    = rel_doc
           relationtype = 'URL'
       EXCEPTIONS
           OTHERS       = 1.
    CASE sy-subrc.
       WHEN 0.
           MESSAGE s043(sgos_msg). " The attachment was successfully created
           RAISE EVENT commit_required.
           RAISE EVENT service_succeeded
                 EXPORTING eo_service = me.
       WHEN OTHERS.
           MESSAGE s042(sgos_msg). " The attachment has not been created
    ENDCASE.
    I hope this is helpful to you even though your initial implementation was a while back. Thanks for replying to my question though!!
    Cheers,
    Amy

  • Java 1.4.1 - Could not reserve space for object heap - need help

    I know this problem has been posted before, but I thought this was fixed in release 1.3. I'm using Windows XP/Professional and do the following:
    C:java -Xmx2g
    Error occured during initialization of VM
    Could not reserve space for object heap
    C:java -version
    java version "1.4.1_02"My computer system has 1 GB of RAM and a 2 GB pagefile, expandable to 3.5 GB. I can get going with -verbose:gc -Xmx1600m -Xms200m, but the GC only gets to about 1 GB before I get an out of memory exception, not even close to 1.6 GB as specified.
    I'd really appreciate it if anyone can shed some light on this behavior.
    Cheers, Eric

    Hmm.
    I tried a mini no-operation application with jdk1.3.1 on Linux. It run okay like this:
    $ java -Xmx1934M u
    $ echo $?
    0
    $ java -version
    java version "1.3.1_07"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_07-b02)
    Java HotSpot(TM) Client VM (build 1.3.1_07-b02, mixed mode)
    $ cat u.java
    class u {
    public static void main(String a[]) {
    $This however fails miserably:
    $ java -Xmx1935M u
    Unexpected Signal : 11 occurred at PC=0x401a0cb7
    Function name=start_thread__2osP6Thread
    Library=/usr/lib/jdk1.3.1_07/jre/lib/i386/client/libjvm.so
    Current Java thread:
    Dynamic libraries:
    08048000-0804c000 r-xp 00000000 03:08 174723     /usr/lib/jdk1.3.1_07/bin/i386/native_threads/java
    0804c000-0804d000 rw-p 00003000 03:08 174723     /usr/lib/jdk1.3.1_07/bin/i386/native_threads/java
    40000000-40012000 r-xp 00000000 03:08 20686      /lib/ld-2.2.5.so
    40012000-40013000 rw-p 00011000 03:08 20686      /lib/ld-2.2.5.so
    ...This looks familiar:
    $ java -Xmx2000m u
    Error occurred during initialization of VM
    Could not reserve enough space for object heap

  • WAN replication not working for objects

    I am trying out the WAN replication example from the Tangosol website. I got the Boston-London example working. However, it seems to only work for simple types like String, int, etc. Objects like hibernate, compressed string are not replicated across. Is more config added for this to work?

    Hi Sham,
        In one of environment we are using publish and author server. Custom comments are replicating on Author environment.  We are not using custom workflow or JCR observation.Created one more environment for Production setup where 2 publish and 1 author instance. For this comment are not auto replicated on Author instance.
    Default comment modification and comment activation launcher are in place, no change in this. Does it not working due to additional Publish Instance and if so what additional setting will required to address it ?
    Thanks
    Yogesh

  • Error: For object RF_BELEG 9000, number range interval 92 does not exist FB

    Hi,
    When I am executing AFAB in test run mode for a particular company code I am getting below mentioned error:
    +For object RF_BELEG 9000, number range interval 92 does not exist FBN1+
        +Message no. NR751+
    +Diagnosis+
        +The database table NRIV has the delivery class 'C', i.e. the SAP default+
        +settings are only in client 000.+
    +Procedure+
        +Create the missing number range interval in customizing.+
        +Transaction code: FBN1+
    When I maintain number range 92 this error goes away. My question is we have no where assigned this number range 92 to any of the Document type then why system is asking to maintain the same?
    Sanjay

    Hi,
    You might be using the number range (say 92 which you've created in GL view & not in ENTRY view).
    Steps:
    Go to Define Document Number Ranges for Entry View OR use T-code FBN1.   Maintain & Assign two Number Ranges say 91 & 92 one for Document Type AF and another for AE for both the non-leading Ledgers say Y1 & Y2 ( Define Document Type for Entry VIew in a ledger). Also assign a number range to
    Document type SX (Closing Posting) apart from the above two Number Ranges (91 & 92)
    Hopefully it works for You............
    Dipti

  • ORA-23454: flavor not defined for object group "PUBLIC"."REPG" - HELP

    Hi All,
    Encountered the below error when trying to add the materialized views to the Materialized View Group in materialized view site:
    1 BEGIN
    2 DBMS_REPCAT.CREATE_MVIEW_REPOBJECT (
    3 gname => 'REPG',
    4 sname => 'FMCHC',
    5 oname => 'EMP',
    6 type => 'SNAPSHOT',
    7 min_communication => TRUE);
    8* END;
    SQL> /
    BEGIN
    ERROR at line 1:
    ORA-23454: flavor not defined for object group "PUBLIC"."REPG"
    ORA-06512: at "SYS.DBMS_SYS_ERROR", line 105
    ORA-06512: at "SYS.DBMS_REPCAT_UTL", line 452
    ORA-06512: at "SYS.DBMS_REPCAT_UTL", line 468
    ORA-06512: at "SYS.DBMS_REPCAT_SNA_UTL", line 5523
    ORA-06512: at "SYS.DBMS_REPCAT_SNA", line 82
    ORA-06512: at "SYS.DBMS_REPCAT", line 1332
    ORA-06512: at line 2
    I have verified that the MASTER DEIFINATION SITE already have the group "REPG"
    Pleae advise.
    THANKS

    I think you are going to have to provide Oracle version information before anyone will be able to help you with this question.

Maybe you are looking for