Polymorphism -- This should be easy right --- or am I missing somthing obvi

Hello from sunny Wales,
I thought the polymorphic capabilities of Java would allow this. Am I doing something wrong.
For the example below assume that value and value2 are strings representing some value be it a decimal (Double) or a String. That we have already worked out what data type resides in the strings value and value2 as stored in the variable type.
With this code my compiler is telling me that the operator >= cannot be used on Object x. I thought that this object would now be handled as a Double due to polymorphism.
This is possible right?? or am I missing something really obvious?
Code:
=============================
Object x;
Object y;
if ( type.equals("double"))
x = new Double (value);
y = new Double (value2);
else (type.equals("String"))
x = new String(value);
y = new String(value2);
boolean b = x >= y;================================
Thanks
Andrew.
Message was edited by:
scottie_uk

Hello.
This is possible right?? or am I missing something really obvious?It's not possible. You are missing a number of things.
* Polymorphism means that you can call a method that is defined in a superclass or interface that is the declared type (e.g. Object) and the implementation of the actual type (e.g. Double, String) gets called. For example, Object has a toString(), which means you can call that method on an Object and whichever actual implemention gets called. It does not mean that the compiler would allow you to call a method on an Object variable that is not defined in class Object. Otherwise, you could call anything on anything.
* Object does not define operator >=, and in fact Java does not support operator overloading. String has some operator support (not >= though) but that's it. Class Double also does not support any operators.
* In Java 1.5 however, there is a feature called autoboxing which converts primitives (e.g. double) to wrappers (e.g. Double), and because of this conversion it effectively appears you can use operators on these wrapper types.
Now, there is a way to accomplish what you want, by using interface Comparable. Both Double and String implement this interface.
Comparable x;
Comparable y;
if ( type.equals("double"))
x = new Double (value);
y = new Double (value2);
else if(type.equals("String"))
x = new String(value);
y = new String(value2);
int diff = x.compareTo(y);
boolean b = (diff >= 0);
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Comparable.html
Message was edited by:
Loko

Similar Messages

  • This should be easy! How can I change the background colour of my fields?

    Apologies if this has already been posted but nothing has come up via Google nor the Forum search.
    I'm sure this should be easy but it's really doing my head in!
    I have a number of textboxes, dropdown lists, etc within my form - I have set Custom backgrounds on each which are visible within Design View. However, in Preview PDF all the fields have a default blue colour and only change to my Custom backgrounds when you enter the field.
    Is there a way of removing the default colouring of fields so that it's the same as my Custom backgrounds? My Custom backgrounds are 'linear to bottom' so I don't want to just set border.fill.color to one colour.
    Thanks for any help,

    Hi,
    If you include this Javascript in the docReady event of the root node (default "form1").
    app.runtimeHighlight = false;
    This will turn off the field highlight. It doesn't prevent the user from turning back on the highlight, but it will mean that your form opens with the highlight off.
    Hope that helps,
    Niall
    Assure Dynamics

  • HELP! I have a work deadline and this should be easy!

    I am at work-big presentation tomorrow-someone sent me an Indesign file and I can't cut and paste the image from indesign to power point. I am selecting the image-right clicking copy and pasting and nothing is working. I have tried to export the image and I can't even do that! I am NEW to indesign-anything that I am missing that is obvious-please let me know!
    Thanks!!!!!

    Thanks for the input. I know PowerPoint really well, but I'm trying to make InDesign documents now for the office. They want me to create great presentations, but Powerpoint is just a horrible application. I was trying to see if there was a way to convert between InDesign and PPT, just so I could use a better application to lay things out and then import it into PowerPoint so other users could work with it.
    Easier said than done.
    The best way I've seen is to follow these steps (I'm using InDesign and Illustrator CS2 and Powerpoint 2002):
    - First, you need to make an InDesign file (where you're doing your designing) and a blank Illustrator file set to the dimensions of a PowerPoint slide (which is 10 x 7.5)
    - After designing your presentation in InDesign, select all the elements on one page (CTRL + A)
    - Copy and paste those elements into your blank Illustrator file
    - Select File > Save For Web
    - Choose PNG and mark the checkbox for transparency
    - Click on the "Image Size" tab
    - Mark the checkbox for antialiasing
    - Increase the scale of the image to about 132%.
    - Save it
    - Paste it into PowerPoint (I like to drag it from my desktop and drop it into the slide)
    - The image you made should fit your powerpoint slide. I don't know why you have to increase the scale of the PNG file when your Illustrator file is the same size as the PPT slide, you just do. You will probably have to still reduce the size of your image slightly, but the resolution should be sharp.
    - Repeat these steps for all the other pages of your InDesign document
    The resolution, typography, and layout of everything is decent, however, there are a lot of drawbacks to this method. Your customer can't edit any text elements because they're all PNG files. You also can't animate each element separately (unless you only chose to export only a selection to PNG from Illustrator, then animate that piece).
    I'm pretty disappointed that there's not direct way to do this that will let the end users of PowerPoint regain control of the document to edit it or change animations, etc. I really hate PowerPoint.

  • This should be easy ;O) How do I read the exif info in a JPG file?

    Hey all...
    I have been googling this for awhile now with not much luck.
    !st... Hi... I am a Flex AS3 newbie....  but... not a programming newbie...
    My learning project is to create my photoart gallery as a Before and After gallery. Part one is a Flex/Air app to gather the images, scale them to consistant display and thumbnail sizes and build and edit XML data files for the images and galleies. I have actually gotten most of that done..
    I am currently working on editing the XML files for the image information (photographer info, copywrite info, descriptions, gallery...etc.) and pulling in as much information that I can find in the image file itself. That being EXIF data.
    I have found a couple of examples but for the XResolution and Yresolution I just keep getting 72dpi... now the Jpg files that I am using from my camera.. when I look at the properties with Windows XP... it say 300dpi... when I load the image in Photoshop and look at image size it says 300dpi.. in Photoshop if I look at file information the EXIF says 300dpi....
    How can I access that data with Flex/AS3????? After all this is "Adobe" Flex Builder...
    This just seems like it should have been solved ages ago... Please.. point to the right path  ;O)
    I have searched this forum and have found one or two EXIF references, but no answers.
    Thanks for any guidance on the subject.
    Bob Galka

    Jean-Pierre
    Thanks very much for your quick response.
    One last point and we should drop this in favor of other more urgent issues we both ahve to deal with.
    The data is coming from a comma delimited (CSV) file using a comma ',' and optional quotes (") as field separators.
    The first column of 'good' data is read as an INTEGER EXTERNAL because of course it is a number. However, the 'bad' rows I want to eliminate have character text in them where I would normally find numbers and they all start with 'D','M' or 'S'.
    I don't have an actual column in the data file or resulting table definition that represents that first character that I'm trying to test on. Hence my use of (1) to reporesent the 1st character of data on the line regardless of whether its numeric or character.
    As I stated, the syntax works fine in SQL*Loader when I typed the WHEN clause in manually.
    I guess if there was a way to define a pseudo column that could be defined using the POSITION notation and everything else using the variable length delimited notation I could test on that psuedo column. I don't want the pseudo column to appear in my resulting table so that seems to be an issue. Enough.
    Since I've worked around it using external tables for this issue I'm not going to spend any more time on it today.
    As usual, many thanks for your help.
    Have a great day! I'll be back soon with another issue :-)>
    Gary

  • I know this should be easy, BUT IT'S NOT!!  help!

    Hey everyone,
    I decided to swallow some pride and find some solution to my situation that should be simple. I've looked on many of the threads and still can't seem to find the solution.
    I am just trying to set up my Airport Express to my Powermac G5. Very simple... just want to run the ethernet through the Express from another room.
    I started by plugging in my Express. That was fine, I got a green light. Then when to Setup Assistant... it cannot find a network. After many attempts, still no network. I tried to reset my Express. No luck. I also configured my Express directly to my Powermac, all settings seemed just fine... except when I try to use it how it is supposed to be used, I get nothing. My G5 is reading my Extreme Card okay. So... what in the world am I doing wrong?
    Admittedly, I am no tech whiz when it comes to networking, so naturally, I assumed that this would be a simple and quick installation... that has seemed to last for hours and hours...
    Powermac Dual 2Gh G5, 4G RAM   Mac OS X (10.3.9)  

    Hi
    I had the same or similar problem when I first hooked up my airport. I took my computer to the Apple store to be sure my airport setup was correct. When they turned on my computer it immediately connected to their network. They had no idea why it wouldn't work at home. I was lucky that a person was standing there that had an idea what was wrong. He said it was possible that there was some interference in my home. So, the apple people suggested that I change from automatic to a specific channel. That was fine, except I asked them how could I do that if the computer didn't recognize the base station? So, we then tried hooking the base station up directly to the computer using an ethernet cable, and it worked (they had never tried this). When I got home I did this and changed the channel to 2 (you have about 10 or so channels you can try). I then put the base station back to the room where my cable is. The computer immediately recognized it. I now have three airport extremes in various rooms and they all work great, as long as I set them to a specific channel. You can try each channel and then check the strength of the signal to determine which is the best for your environment.
    Hope this helps.
    Larry

  • Help please! (This should be easy)

    Ok, so my father set up our printer on the wireless network yesterday. His windows based computer can print fine with it. I'm trying to get my Apple to work with it now. I have a word document up, and I select to add a new printer, I search for it, find it, add it, and then print. Everything seems okay so far, but instead of printing my document, it prints 12 blank pages, and 1 page with randomly assorted letters (code?) on it. Sooooooo.... what should I do? Thanks!!

    Eh, getting help usually means someone has had a similar issue, and also makes forays into these discussion boards.
    That being said, I've never had that problem, but I'll try to help...
    So, I'm assuming the printer software is installed on your Mac? Or it's one that is already compatible with your computer. I guess you should check your printing options that pop up when you try to print. If everything seems ok there, I'd try downloading drivers from the printer company's website and reinstalling the drivers.
    Hope this helps

  • Mute the input monitor while recording? Should be easy, right?

    First off, here's an illustration of what I'm doing:
    http://www.thesoundofmachines.com/re-amp-image.jpg
    I'm sending an already recorded guitar take through a cigar-box amp, then re-recording it back into a new track in the logic session at the same time.
    I did search the forums & the user manual. I must be loosing it. How do I mute the input signal while it's being recorded? I need the input to be recorded, but not monitored. Otherwise, I'm drowning in a terrible feedback loop.
    I turned off "software monitoring" to no avail. What am I missing?
    Thanks in advance...
    -Should Know This Stuff

    Heya- take a look at this:
    http://www.thesoundofmachines.com/re-amp-image.jpg
    You can see it's just a little Edirol USB interface.
    http://www.roland.com/products/en/UA-1A/index.html
    I know! I need better! I just don't have extra money at the moment.
    So any tips or suggestions? (other than "buy a new interface...")
    Thanks!

  • Percentile in a collection. This should be easy but....

    I want to find the 80th percentile in the list of numbers in a collection.
    I have loaded data into a nested table:
    Type type_NumTable is TABLE OF Number;
    tbl_LocalScores type_numTable := type_numTable();
    I thought I could use Table() to accomplish this; however, the following comand
    select trunc(PERCENTILE_CONT(.80)) WITHIN GROUP (ORDER BY column_value DESC))
    into LocalTolerance
    from Table(tbl_LocalScores);
    gives me an error of
    320/52 PLS-00642: local collection types not allowed in SQL statements
    320/46 PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    320/5 PL/SQL: SQL Statement ignored
    Can someone give me a hint as to what I'm missing or a suggestion on how to accomplish finding the 80th percentile within a collection.
    Thanks
    Larry

    user6282899 wrote:
    Can someone give me a hint as to what I'm missing or a suggestion on how to accomplish finding the 80th percentile within a collection.Well, hint is in the error message - do not use local collection types. Use SQL types. For example:
    CREATE OR REPLACE Type type_NumTable is TABLE OF Number;Or better use oracle defined type sys.OdciNumberList:
    declare
        tbl_LocalScores sys.OdciNumberList := sys.OdciNumberList(1,3,17,22,25,99,56);
        LocalTolerance number;
    begin
        select  trunc(PERCENTILE_CONT(.80) WITHIN GROUP (ORDER BY column_value DESC))
          into  LocalTolerance
          from  table(tbl_LocalScores);
          dbms_output.put_line(LocalTolerance);
    end;
    5
    PL/SQL procedure successfully completed.SY.

  • Trying to Create an Edit Form .... UGGGHHHHH ... this should be easy.

    I have been through about 5 iterations of this problem and can't find a successful solution. I have a list that contains everything I need. I want to allow users to edit only two fields in the list and look up a particular entry. It's a simple lookup in
    ASP.Net. I cannot find a way to do this that's successful. My boss wants to extremely limit what the user sees and can update. Here were my attempts:
    1. Dataview in SharePoint list - Problem - Too open for the user to have access to other list fields and no way to filter
    2. WebPart in SharePoint - Problem - The list is located in a sister site under the site collection and the gymnastics were too difficult
    3. InfoPath Form - Problem - This was the most promising, but since the list was located on another site, I could not get the list to update. I used this as a basis for the form. http://jaliyaudagedara.blogspot.com/2011/03/submitting-data-to-sharepoint-2010-list.html
    4. SharePoint Custom Edit - Problem - This worked well, but relied on multiple pages. Boss thought it was too complicated. But it worked. I liked it but the list edit opened a page and ... not simple enough.
    Is there a way I haven't thought of? I would like to use something like a simple drop down to choose the vendor display vendor name and number (read only) and be able to edit the email and portal info and update the record (see image). This has to be doable
    in a simpler way than I am doing. 
    Jef

    The first image is an InfoPath form that assigns values in code to the value. It says it works, looks like it works but the values don't get written. I'll include the code.
    What my boss doesn't like for option 4 is the attached image. He thinks it will confuse our users. I tend to agree. You can't type in the field either. I'm not sure how I can pass a value from a drop down list to the web part. If I knew that I'd be done.
    using Microsoft.Office.InfoPath;
    using System;
    using System.Xml;
    using System.Xml.XPath;
    namespace Sym
    public partial class FormCode
    // Member variables are not supported in browser-enabled forms.
    // Instead, write and read these values from the FormState
    // dictionary using code such as the following:
    // private object _memberVariable
    // get
    // return FormState["_memberVariable"];
    // set
    // FormState["_memberVariable"] = value;
    // NOTE: The following procedure is required by Microsoft InfoPath.
    // It can be modified using Microsoft InfoPath.
    public void InternalStartup()
    ((ButtonEvent)EventManager.ControlEvents["UpdateBtn"]).Clicked += new ClickedEventHandler(UpdateBtn_Clicked);
    public void UpdateBtn_Clicked(object sender, ClickedEventArgs e)
    // Write your code here.
    try
    XPathNavigator root = MainDataSource.CreateNavigator();
    XPathNavigator myNavigator = this.DataSources["Supplier Routing Receive"].CreateNavigator();
    // Retrieve the values for the separation list item
    string ListName = root.SelectSingleNode("/my:myFields/my:ListName", NamespaceManager).Value;//Setting the GUID
    string eTitle = myNavigator.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Title", NamespaceManager).Value;
    string eVName = myNavigator.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Vendor_x0020_Name", NamespaceManager).Value;
    string eWebPort = myNavigator.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Supplier_x0020_Web_x0020_Portal", NamespaceManager).Value;
    string eEmailDS = myNavigator.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Supplier_x0020_Email_x0020_Addre0", NamespaceManager).Value;
    //if ((eWebPort == "Yes") || (eWebPort == "No"))
    //else
    // MessageBox.Show("Supplier Web Portal must be either Yes or No");
    if (ListName == null)
    else
    //This is CAML xml file. it contains batch and method nodes
    XPathNavigator batch = DataSources["Submit"].CreateNavigator();
    batch.SelectSingleNode("/Batch/Method/Field[@Name='Title']", NamespaceManager).SetValue(eTitle);
    batch.SelectSingleNode("/Batch/Method/Field[@Name='Vendor Name']", NamespaceManager).SetValue(eVName);
    batch.SelectSingleNode("/Batch/Method/Field[@Name='Supplier Web Portal']", NamespaceManager).SetValue(eWebPort);
    batch.SelectSingleNode("/Batch/Method/Field[@Name='Supplier Email Address for Info Requests']", NamespaceManager).SetValue(eEmailDS);
    DataConnections["Web Service Submit"].Execute();
    // MessageBox.Show(batch.SelectSingleNode("/Batch/Method/Field[@Name='Supplier Email Address for Info Requests']", NamespaceManager).Value.ToString());
    catch (Exception ex)
    // MessageBox.Show(ex.Message.ToString());

  • Safari question...this should be easy

    For some reason, the google window in safari no longer remembers "recent searches". And I haven't cleared any of them. Any suggestions? Thanks!

    She suggested I do an archive and install.
    That's kind of the road I was going down if it didn't work on a new user account. Unfortunately, it looks like it's come to that. Hopefully it'll fix the issues!
    I'll report back to tell you if that fixes the glitch
    or not.
    Sounds good! *Fingers crossed*
    -Ryan

  • I have restored my 1st gen out of the box ipad and can still not connect to anything.wi-fi is enabled and strong.i am losing my mind.forgive me this is my first apple product and this startup should have been easy right?what else do I do?Help!

    I have an ipad that I can not get to connect to anything.Keep getting "server stopped responding" after ipad tries to connect for 5 minutes.I have wi-fi enabled and password given and enabled with strong signal.I have restored to factory settings once allready.I am an Apple newbie as this is my first product experience and it is not going very well.This should be easy and I must be doing something wrong or I have a defective ipad.I have the latest software installed and have itunes connected through my laptop.I am losing my wits and could use some help since I am lost with what to do now.Help?

    If your Laptop is using windows... Try this...
    Temporarily disable your firewall and antivirus software and try again...
    See here for Connection Issues
    http://support.apple.com/kb/TS1379
    From Here
    http://www.apple.com/support/itunes/troubleshooting/

  • In the Firefox browser, when i click button in ADF page, then popup  the OAF page in iframe tag,and then when i  click the PPR bean in  OAF page, then Firefox  browser reload to ADF page. This is not the right response,browser should not reload the ADF pa

    In the Firefox browser, when i click button in ADF page, then popup  the OAF page in iframe tag,and then when i  click the PPR bean in  OAF page, then Firefox  browser reload to ADF page. This is not the right response,browser should not reload the ADF page.It should stays in OAF page or goto another OAF page. and in other browser such ad IE,We get the right response.

    hello, normally such issues are caused by a firewall/security software which doesn't recognize & therefore blocks new firefox versions. please remove all program rules for firefox from your firewall and let it detect the new version of the browser again.
    [[Fix problems connecting to websites after updating Firefox]]

  • JSPs reference to JPEGs .. this should be an easy one!

    Hi,
    We are moving our 6.20 java apps to NW04S J2EE apps. So, we have created EJB, Web and EAR projects for this.
    In NWDS, we have used Import File to bring in all of our JSPs. NWDS stores them under the webContent folder in the Web project. Each JSP refers to /DCT/images/<filename>.jpg.
    We have also used Import File to bring in the 6.20 images folder. In the project it is under /webContent/DCT/images.
    When we preview the JSPs, the images do not show up unless we change the reference in the JSP to DCT/images<filename.jpg (no leading slash). Since there are so many JSPs we do not want to change the references in the JSPs.
    Two issues we found:
    1. We can only create a folder structure under webContent. It seemed to us that we would need to create /DCT/images at the project root.
    2. In preview mode, when we right click -> propeties on the missing jpgs it says the jpg should be at c:\DCT\images. It is completly ignoring the file structure of our project.
    Any clues to this mystery would be greatly appreciated.
    Cheers ... Bart

    "garywpaul" <[email protected]> wrote in
    message
    news:f9f35h$n0t$[email protected]..
    > Well, I tried it with a jpg and it just opened. Is this
    the same thing
    > that
    > will happen with PDF files?
    If you link directly to a PDF, and the user has Adobe Acrobat
    installed
    (which the vast majority do), it will open within the browser
    in Acrobat
    Reader. The user can then choose to click the Save button and
    save it to
    whatever location he wants.
    This should be fine for a restaurant menu. This was, the user
    can look at
    the menu online to his heart's content, and only save it if
    he really wants
    to have a local copy. (You might include, near the link, a
    very brief
    one-line instruction.)
    > I would like for the dialog box to open (Save file
    > as) and the file be saved on the visitors computer.
    If that's what you really want, you can zip the PDF into a
    zip file, and
    link to the zip file. That way, the user will get the dialog
    box that you
    want.
    Patty Ayers | Adobe Community Expert
    www.WebDevBiz.com
    Free Articles on the Business of Web Development
    Web Design Contract, Estimate Request Form, Estimate
    Worksheet

  • My 4th Generation iPod Touch takes 480 x 640 pictures?! How can I up this resolution? It should be higher, right?

    Hello there!
    This vacation I made pictures with my iPod touch (back-camera) but somehow the pixels I get on the pictures when I sync with my MacBook Pro are 480 x 640?! How can I up this resolution (either on the camera, or on the already taken pictures)? It should be higher, right?
    Thank you in advance for your reply!
    Pieter Kroon

    Ehmm... okay, after reviewing I understand what is going on. Some of the pictures are taken by the front facing camera and the back-facing camera is just not very good... It seems everything is good I am sorry for asking this stupid question, I should've investigated things further.
    Anyway, thank you very much for your reply.

  • HT1423 i am replacing ram in an early 2009 imac. easy - right? but the pulling on the tabs didn't work. i have had the ram sticks out before; but now they don't budge. should i apply more pressure? use a tool to pull harder? will the tabs break off?

    i am replacing ram in an early 2009 imac. easy - right? but the pulling on the tabs didn't work. i have had the ram sticks out before; but now they don't budge. should i apply more pressure? use a tool to pull harder? will the tabs break off?
    sorry for the format - my 1st question...

    thanks Kappy.
    the computer has beem working for years after my 1st ram removal; but i may have pushed them back too hard. i did pull firmly - tried pulling up slightly; tried tugging on the sides of the stick; pulling in pulses. the only thing i have not tried is using needle nose plyers with protection on the tab film itself.
    have you had the pulling harder ever work? or break the tab?

Maybe you are looking for

  • How to use Add Query Criteria for the MySQL data Base in Netbeans ?

    How to use Add Query Criteria for the MySQL data Base in Netbeans Visual web pack. When the Query Criteria is add like SELECT ALL counselors.counselors_id, counselors.first_name, counselors.telephone,counselors.email FROM counselors WHERE counselors.

  • Is there a way to modify the schema-mapped XML that is generated by the submit action prior to submission?

    I have a form created in LiveCycle ES2. I have mapped some fields to a schema that causes LC to generate XML that adheres to the import format of one of my company's internal databases. There is one problem: the system's import function looks for a D

  • Get email ID

    HI,     How to get the email id of the currently logged in user, using webdynpro for java 2004. How to send an email using webdynpro for java with attachments.

  • Interface expense reports from Payables

    Hi, We are using projects based expneses in our iExpense module. This flows into Accounts payable and then we have a nightly process that pulls the expnese report that satisfies certain criteria. Does the expense reports needs to be accounted, paid a

  • Playing Game in Other Profiles

    Good afternoon, I recently installed a game for my daughter on my Powerbook but she is unable to play it from her profile. The message states that "You are unable to play the game from a locked or write protected volume." I'm not quite sure what this