Reference equality for X and Integer

Hi,
my problem is that i'd like to understand why java won't accept this statement at compile time.
Class X { .... }
Class Y {
   doSomething(...) {
      X x1;
      Integer i;
      boolean b = i == x1;
}I absolutly know that this code makes no sense but I don't understand my java won't compile this type of code. The problem is the comparsion of Integer and X but they are both objects so why doesn't it word?
If I use another variable with the type of Y the comparsion would be executed at runtime.
Thanks a lot
Jonny

You are trying to compare references of types that are incompatible.
Here is the relevant part of the Java Spec on == (Section 15.21.3):
"A compile-time error occurs if it is impossible to convert the type of either operand to the type of the other by a casting conversion (5.5). The run-time values of the two operands would necessarily be unequal."
Some other commenter recommended using equals, which of course, will never return true in this case and probably throw a runtime exception anyways.
They might want to re-read my comments in the Topic Java app disobeying 'if' structure abort the importance to understand the difference between == and Object.equals.

Similar Messages

  • Is there a difference between microsoft office for mac and for windows?

    As a college student it's important that everything is equal for windows and mac for using instructions. So i am wondering if theres a difference between microsoft office for mac and for windows?

    There are differences between the two version of Office. If you need to be exactly like the Windows version, you will have to run Windows on your Mac.
    Allan

  • Reference object in Notification and Order

    Hi ,
    I have a requirement to capture following in the reference Object for notification and  Order
    1. Functional Location
    2. Equipment
    3. Material
    4. Serial Number
    Configuration setting for overview of notification type doesn't have  the option to capture all the above fields.
    I am able to get all fields except Functional Location...
    Please guide me
    Regards
    Anil Kumar

    Anil,
    I have just been looking at this same requirement.
    Unfortunately you can only use the standard options for reference objects which does not allow for your requirement.
    There are no user-exits/BADIs either, you would need to build a new screen and screen-logic which is a system modification.
    The best I could do within the standard system is to include these fields on the Enhancement tab (user-exit IWO10018) or build a bespoke front-end via ABAP or HTML. GUIXT is another option.
    PeteA

  • Reference field for quantity/currency

    why s that we need to give a reference field for quantity and currency based fields alone

    hi,
    The reference field is used for the output, the output/input format of a currency field depends on the value of its reference field.
    For example if you create a screen using the field KONV-KBETR :
    the reference field is RV61A-AWEI1:
    if you set RV61A-AWEI1 = 3
    the value in KONV-KBETR is beeing shown with 3 decimals
    So you could see 3,000 but this value is automatically stored as 30.00
    if you set RV61A-AWEI1 = 2
    the value in KONV-KBETR is beeing shown with 2 decimals
    All this convertions are automatically made in according to the value setted in reference field.
    You can see this using the statament WRITE with options CURRENCY, try this:
    PARAMETERS P_KBETR LIKE KONV-KBETR.
    WRITE: P_KBETR CURRENCY '3'.
    WRITE: / P_KBETR CURRENCY '2'.
    WRITE: / P_KBETR CURRENCY '1'.
    Rgds
    Anver

  • Object and reference accessing for primitives, objects and collections

    Hi,
    I have questions re objects, primitives and collection accessing and references
    I made a simple class
    public class SampleClass {
         private String attribute = "default";
         public SampleClass()
         public SampleClass(SampleClass psampleClass)
              this.setAttribute(psampleClass.getAttribute());
              if (this.getAttribute() == psampleClass.getAttribute())
                   System.out.println("INSIDE CONSTRUCTOR : same object");
              if (this.getAttribute().equals(psampleClass.getAttribute()))
                   System.out.println("INSIDE CONSTRUCTOR : equal values");
         public void setAttribute(String pattribute)
              this.attribute = pattribute;
              if (this.attribute == pattribute)
                   System.out.println("INSIDE SETTER : same object");
              if (this.attribute.equals(pattribute))
                   System.out.println("INSIDE SETTER : equal values");
         public String getAttribute()
              return this.attribute;
         public static void main(String[] args) {
    ...and another...
    public class SampleClassUser {
         public static void main(String[] args) {
              SampleClass sc1 = new SampleClass();
              String test = "test";
              sc1.setAttribute(new String(test));
              if (sc1.getAttribute() == test)
                   System.out.println("SampleClassUser MAIN : same object");
              if (sc1.getAttribute().equals(test))
                   System.out.println("SampleClassUser MAIN : equal values");
              SampleClass sc2 = new SampleClass(sc1);
              sc1.setAttribute("test");
              if (sc2.getAttribute() == sc1.getAttribute())
                   System.out.println("sc1 and sc2 : same object");
              if (sc2.getAttribute().equals(sc1.getAttribute()))
                   System.out.println("sc1 and sc2 : equal values");
    }the second class uses the first class. running the second class outputs the following...
    INSIDE SETTER : same object
    INSIDE SETTER : equal values
    SampleClassUser MAIN : equal values
    INSIDE SETTER : same object
    INSIDE SETTER : equal values
    INSIDE CONSTRUCTOR : same object
    INSIDE CONSTRUCTOR : equal values
    INSIDE SETTER : same object
    INSIDE SETTER : equal values
    sc1 and sc2 : equal values
    ...i'm just curios why the last 3 lines are the way they are.
    INSIDE SETTER : same object
    INSIDE SETTER : equal values
    sc1 and sc2 : equal values
    how come while inside the setter method, the objects are the same object, and after leaving the setter method are not the same objects?
    Can anyone point a good book that shows in detail how objects, primitives and collections are referenced, especially when passed to methods. Online reference is preferred since the availability of books can be a problem for me.
    Thanks very much

    You are confusing references with objects.
    This compares two object references:
    if( obj1 == obj2 ) { // ...Whereas this compares two objects:
    if( obj1.equals(obj2) ) { // ...A reference is a special value which indicates where in memory two objects happen to be. If you create two strings with the same value they won't be in the same place in memory:
    String s1 = new String("MATCHING");
    String s2 = new String("MATCHING");
    System.out.println( s1 == s2 ); // false.But they do match:
    System.out.println( s1.equals(s2) ); // trueIf you're using a primitive then you're comparing the value that you're interested in. E.g.
    int x = 42;
    int y = 42;
    System.out.println(x == y); // trueBut if you're comparing references you're usually more interested in the objects that they represent that the references themselves.
    Does that clarify matters?
    Dave.

  • PLEASE: How can I save my iphone texts and "notes" (not "the note") to my computer? I need them for reference and legal purposes. I have yet to find an app for this and iphone doesn't sync either one.

    Greetings!
    I am brand new to using a Support Community -- I'm more of a in-person show me learner but...huge snowstorm and I don't want to
    to make an appointment at a Genius Bar, driving 15 miles, especially since I asked about this once before  and no one there was able to
    give me an "official" Apple answer .  I do hope I am posting my question (and plea) for help properly.
    LOL when I had my first lil' Mac Classic, over 20 years ago, my participation in the techno world was soooo much easier, simpler.
    My current situation: I have soooo many texts on my iphone and I haven't deleted many because I need the information contained in them for
    future reference and for legal purposes.  I would really like to find a means and way to save them other than on the phone itself.
    I've done searches for various apps yet I'm not finding what I think I would need.  It appears Apple does not sync the texts between the iphone and
    my MacBook Pro.
    Also I often use Notes for quick journaling as well as copy and pasting from other apps, usually inspirational, that I know I am going to want
    to read again (always with credit noted ) and these too are taking up space.  If I could email myself I would but the apps I'm using don't offer that and each day there is a new commentary -- no way to go "back".
    I am currently using OS 10.6.8 on my MacBook -- my disc drive doesn't work and upgrading has to be done at the Apple Store so I don't have iCloud yet.
    My iphone 4  is running OS 6.0.1 -- no upgrade until I'm at a wifi connection -- most of the time I'm using my personal hotspot.
    I'm a very busy self-employed Nana raising grandchildren and a great-grandchild.  I don't have a lot of time and certainly not enough for copying and pasting every text as well as note and emailing it to myself.  There has got to be a better, easier way, yes?
    I'd be most appreciative of any and all assistance here.  Oh, someone mentioned to me I ought to get a "stick" for downloading but were talking
    in a language I'm still learning. 
    Thank you!
    Melinda

    SkyDaughter29 wrote:
    My current situation: I have soooo many texts on my iphone and I haven't deleted many because I need the information contained in them for future reference and for legal purposes.  I would really like to find a means and way to save them other than on the phone itself. I've done searches for various apps yet I'm not finding what I think I would need.  It appears Apple does not sync the texts between the iphone and my MacBook Pro.
    Try the computer apps PhoneView (Mac) or TouchCopy (Mac & PC):
    http://www.ecamm.com/mac/phoneview/
    http://www.wideanglesoftware.com/touchcopy/index.php
    Best of luck.

  • C# compiling error: 'System.Array' does not contain a definition for 'Select' and no extension method 'Select' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

    Hello experts,
    I'm totally new to C#. I'm trying to modify existing code to automatically rename a file if exists. I found a solution online as follows:
    string[] allFiles = Directory.GetFiles(folderPath).Select(filename => Path.GetFileNameWithoutExtension(filename)).ToArray();
            string tempFileName = fileName;
            int count = 1;
            while (allFiles.Contains(tempFileName ))
                tempFileName = String.Format("{0} ({1})", fileName, count++); 
            output = Path.Combine(folderPath, tempFileName );
            string fullPath=output + ".xml";
    However, it gives the following compilation errors
    for the Select and Contain methods respectively.:
    'System.Array' does not contain a definition for 'Select' and no extension method 'Select' accepting a first argument of type 'System.Array' could be found
    (are you missing a using directive or an assembly reference?)
    'System.Array' does not contain a definition for 'Contains' and no extension method 'Contains' accepting a first argument of type 'System.Array' could be
    found (are you missing a using directive or an assembly reference?)
    I googled on these errors, and people suggested to add using System.Linq;
    I did, but the errors persist. 
    Any help and information is greatly appreciated.
    P. S. Here are the using clauses I have:
    using System;
    using System.Data;
    using System.Windows.Forms;
    using System.IO;
    using System.Collections.Generic;
    using System.Text;
    using System.Linq;

    Besides your issue with System.Core, you also have a problem with the logic of our code, particularly your variables. It is confusing what your variables represent. You have an infinite loop, so the last section of code is never reached. Take a look 
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.IO;
    namespace consAppFileManipulation
    class Program
    static void Main(string[] args)
    string fullPath = @"c:\temp\trace.log";
    string folderPath = @"c:\temp\";
    string fileName = "trace.log";
    string output = "";
    string fileNameOnly = Path.GetFileNameWithoutExtension(fullPath);
    string extension = Path.GetExtension(fullPath);
    string path = Path.GetDirectoryName(fullPath);
    string newFullPath = fullPath;
    string[] allFiles = Directory.GetFiles(folderPath).Select(filename => Path.GetFileNameWithoutExtension(filename)).ToArray();
    string tempFileName = fileName;
    int count = 1;
    //THIS IS AN INFINITE LOOP
    while (allFiles.Contains(fileNameOnly))
    tempFileName = String.Format("{0} ({1})", fileName, count++);
    //THIS CODE IS NEVER REACHED
    output = Path.Combine(folderPath, tempFileName);
    fullPath = output + ".xml";
    //string fullPath = output + ".xml";
    UML, then code

  • Where do i find the reference number for my preorder? and yes i no this is prob a dumb question but i cant find it anywhere......

    Where do i find the reference number for my preorder? and yes i no this is prob a dumb question but i cant find it anywhere......

        Hi droidboy52999,
    Your email won't have the same confirmation number as it was ordered over the phone. You will need the last name used for the order, the location code (this ends in 01) and an order number (five to six digit number). Please keep us posted if you need further assistance with this.
    Thank you,
    MariaC_VZW
    Please follow us on Twitter @VZWSupport

  • Internal and external reference voltage for DAC

    Hi
    For example: If we are using +10V as the internal reference voltage, the range of the DAC would be -10 to +10V. But if the signal goes only from -5 to +5 V, the resolution of DAC is not getting maximized. To maximize the Resolution, an external refernce voltage of +5V can be given. Now the range of the DAQ will be -5V to +5V, same as that of the signal..
    What is internal and external reference voltage for DAC ?????
    Somil Gautam
    Think Weird

    Hi,
    you're better post this question on the "multifunctional DAQ" section, quoting the P/N of your device, as well as your programming language

  • Reference Table and Fields for Units and Currency

    Can anyone advise on what the reference tables and fields are for currency and quantity key figures? Thanks
    I think for currency the table is TCURC and field is WAERS, does this make sense, not sure for the quantity though
    Message was edited by:
            Niten Shah

    Hi try these -
    TCURC          (Currency codes)
    TCURF          (Translation factors)
    TCURN          (Notations)
    TCURS          (Exchange Rate Spreads)
    TCURT          (Description of the Currency Code)
    TCURV          (Exchange rate types for currency translation)
    TCURW     (Use of exchange rate types)
    TCURX          (Decimal places of the currencies)
    Regards
    Vikash

  • Reference Library for Converting Between LabVIEW and XML Data (GXML)

    Please provide feedback, comments and questions on the Reference Library for Converting Between LabVIEW and XML Data (GXML) in this thread.
    The latest version of the NI GXML Library is availble in VIPM on the NI LabVIEW  Tools Network repository.

    Francesco, Thank you for the feedback.  With this component it was my intention to make a more "terse" version of the LabVIEW Flatten to XML VI that was also supported on RT and that gave the user more flexbility regarding the structure of the parsing type definition. I think you are right that the XML parser is not compliant to section 2.11 of the XML spec.  The parser does specifically looking for a #D#A and this appears to be an oversight on my part.  Please confirm for me, the specifcation is saying that the XML parser should be able to recognize three possibilities as an "end of line" character: #D#A, #D, or #A.  Am I reading this right?There are more efficient (and in some cases much more efficient) ways of sharing data between LabVIEW and LabVIEW: some examples are flattened binary strings and the datalog binary format.  XML is slower than these optons but the upside is that it is human readable.  Furthermore XML is inherently hierarchical which is convenient for complex data structures like clusters of arrays of clusters, etc.  If you don't care about human readability then you are correct XML doesn't make as much sense.I will return to the GXML source code and try to fix this in the near future but I would hope that instead of creating yet another custom VI from scratch that you could reuse what I have provided for you.  I included enough documentation in the source code so that users could make some modificiations themselves. The target application for this reference library was LabVIEW to LabVIEW communication.  As such I documented the schema on the dev zone document from a LabVIEW perspective.  It includes all the supported datatypes and all the supported data structures (cluters, arrays, multidimensional arrays, clusters of multidimensional arrays, etc.)  I do see some value in making a more conventional XML spec but the time investment required didn't really line up with my intended use case. Were there any other downsides to GXML that I have missed?  Best Regards, Jeff TippsSystems Engineer - Sound and VibrationMessage Edited by Jeff T. on 04-21-2010 10:09 AM

  • LSMW for Routing and Reference Operations

    Hello Experts,
    I am working on data transfer for Routing and Reference Operations (TCode CA01 and CA11).
    I found one LSMW for Routing provided by SAP but didnt found for Reference Operations. Does anyone has more stuff related to Data transfer for Routing and Reference Operation.
    Please share with me. My email id is [email protected]
    Thanks in Advance..
    Harkamal

    Hi Harkamal,
        Check the programs:
    RCPTRA01
    RCPTRA02
    Go to SE38 .
    GIve the name of the program.
    Choose the Documentation radio-button.
    Click Display.
    It is pretty well documented.
    Regards,
    Ravi Kanth Talagana

  • Is there any diffence in rendering websites with safari for windows and safari for mac os, or are both equal?

    Is there any diffence in rendering websites with safari for windows and safari for mac os, or are both equal?
    So is it necessary to buy a mac to guarantee that a website acts like it should, or is the Safari for Windows enough?

    So is it necessary to buy a mac to guarantee that a website acts like it should, or is the Safari for Windows enough?
    Pages render the same for Mac and Windows in Safari.

  • Is there any way to have equal Ukraine keyboard layout for iPad and iMac?

    There are fatal difference between Ukrainian keyboard layouts for iPad and for iMac. Letters «І» and «И» are set vice versa. I would like to have equal Ukraine keyboard layout for iPad and iMac. How I can get it?

    You need to create and restore a backup to transfer the application data.
    (93453)

  • Blah.equals() for ints?

    I know for strings and such you sometimes have to use .equals() since they may not point to the same object but the values may be the same.
    What is the equivalent expression for ints?
    == isn't working, and if I use equals it gives the error:
    "int cannot be dereferenced"
    Edit:
    Wait a minute... if I have two int variables with the same value, I SHOULD be able to use ==, shouldn't I?????????
    Edit 2:
    Nevermind.

    String and int are completely different data types. String is an object and extends the java.lang.Object class in Java. The Object class defines the method equals() which compares references between two Objects and returns true if the references are equal. The String class overrides this method to return true if the content of the Strings being compared is the same.
    To compare int, you can very easily use '=='. Of course it works!

Maybe you are looking for

  • HT1848 How do you transfer music from one authorized computer to an iphone?

    I want to transfer music from my old computer to my iphone, which I have made an authorized computer.

  • Best way to handle text files in OD10g

    We have a requirement to store reports in text format into a database field, to be able to view the reports, and to print them if desired using Forms 10g. What is the best way to handle this? - define the field in the database as clob or blob? - if C

  • How to handle connection to db problems using toplink

    Hi, We need to handle loss of db connection in our application. We use glassfish and toplink essentials (0.22). I suspect that a java RuntimeException is thrown by toplink. This is the code we use to access the db (mysql). The MyServiceImpl class is

  • Multiple Skype Idenities

    Is it possible to be signed in as multiple Skype identities on one computer using Skype Manager? I have an online Skype number for my business but have also taken on a virtual reception role for another business using a separate Skype number. I want

  • WMS Questions  -

    Gurus, Help needed !! We are going live in Oracle WMS system on 11.5.10.2 version very soon. I have few questions of couple of business needs - 1. how can I direct the picker to a Staging Lane (Locator Defined  in Staging Sub Inventory)  for a partic