Why doesn't reflection reveal the clone() method in arrays?

I was surprised to discover that the following code does not reveal the method "clone()", even though you can call "clone()" on an Object[]. Can anyone explain why this is? I was hoping to use the Reflect API to clone an arbitrary object if it was Cloneable, and to throw an Exception otherwise. How can I do this?
import java.lang.reflect.Method;
public class Test {
     public static void main(String[] args) throws Exception {
          Object x;
          //pick a class
          x = new Object[] {};
          //is it Cloneable?
          System.out.print("The class " + x.getClass().getCanonicalName() + " is ");
          if(!(x instanceof Cloneable)) System.out.print("NOT ");
          System.out.println("Cloneable");
          System.out.println("-------");
          //what methods are available?
          Method[] meths = x.getClass().getMethods();
          for(Method m : meths) {
               System.out.println(m.getName());
          System.out.println("-------");
}

Just to clarify. I know that clone() is protected in Object, but it is certainly a public method in array objects such as int[], float[], Object[] etc. Test: call clone() on any of these objects! Also, I realize that Cloneable does not itself guarantee the method clone(). Nevertheless, if you take a regular Cloneable object, such as a String, then typically, if you ran myObject.getClass().getMethods() on that object, you'd find the method clone() in the resulting list. i.e., that Class has overwritten Object's protected clone() method with a public clone() method. So since int[], float[] and all the rest have a clearly public clone() method, then why doesn't myFloatArray.getClass().getMethods() show me a method called "clone"? I guess it would have to have something to do with the fact that arrays are funny kinds of classes that are not properly handled by the Reflection API, but is it on purpose that clone() isn't available?

Similar Messages

  • XmlBean usage and the clone() method.

    I'm trying to use the XmlBean class as the superclass for all our business objects and we have an issue with the usage of the clone method.
    Basically our business objects all throw the CloneNotSupportedException (as per Object.clone() signature) while XmlBean.clone() does not throw it. Introducing XmlBean into the hierarchy will cause quite a bit of effort to change clone() signatures for a lot of classes. So, we were wondering if there is any alternative to subclassing XmlBean while at the same time using the efficient caching that it gives us. I guess I'm looking for a "composition" approach rathe than an "inheritance" approach that might work.
    Has anyone faced this issue and is there any other workaround?
    Thanks,
    --Das                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    The reason that I asked is that the exception is "old baggage" from a design flaw in the original JDK 1.0 .. it is a checked exception that can never happen on an object that implements Cloneable, so if you don't throw it, and you implement Cloneable, then it won't be thrown on clone().
    Peace,
    Cameron Purdy
    Tangosol, Inc.
    Coherence: Shared Memories for J2EE Clusters

  • Why doesn't Apple list the changes in iPhone updates?

    Why doesn't Apple list the changes included with each iteration of iPhone updates? They always post a detailed list of changes for all other major software updates. I wonder why the same is not true for the iPhone, leaving us all guessing and wondering...

    Just to add, Ansuz82 pointed out, Apple's track record is that they don't really ever give full published details about what their updates include in any of their products really. If the iPhone is your first product by Apple you may not be aware of this. To them, saying Bug Fixes is enough. If they publicly add more info, it means they really wanted to get that point out. eg: the 1.1.1 mainly just talked about iTunes WiFi store. 1.1.2 mainly talked about the Tiff exploit fixed and keyboard updates for languages. However, with all, a lot more does get changed than just the key points mentioned. And by a lot, I don't mean a lot that you will see. Have to remember, they are still ironing out the OS for the iPhone. A lot of changes to them is just cleaning up and fixing known bugs that many of us as users may not even know exisit (though we see the outcome of them when apps colide and crash each other).
    Message was edited by: DaVBMan

  • Why doesn't Mozilla fix the Yahoo problem - it is a hacking issue?

    Dozens of people have strongly complained about Yahoo inserting itself in Firefox and hiding itself so it cannot be removed. This has been going on for at least a month.
    Why doesn't Mozilla do something to prevent Yahoo from HACKING into Firefox.? It is an obvious attempt to pre-empt people's browser of choice. Surely there is someone in the Mozilla group who can either alter the code to block Yahoo or at least come up with a solution that lets the average user remove the stupid Yahoo software.
    Thanks

    What a pathetic joke - the instructions to remove the unwanted Yahoo search engine tell you to open up the search engine list and remove Yahoo. BUT YAHOO IS NOT DISPLAYED IT IS HIDDEN AND CANNOT BE REMOVED.
    That horrible fact is what is so annoying. It is willfully hidden by either Mozilla or Yahoo forcing it down the throats of people who do not want it!!
    And a search on one's entire system does not turn up any reference to Yahoo.
    ONE MORE TIME, THIS IS MY COMPUTER NOT MOZILLA'S OR YAHOO'S.
    Please do what you know perfectly well is the right thing to do and provide a viable method for users to get rid of Yahoo.
    Why, Alice, can't you specifically answer my questions instead of spouting the drivel about providing features for a broad range of customers. There are hundreds if not thousands of user that are not happy about this stupid problem.

  • I paid for an in-app purchase of $10 which doesn't reflect in the app but has gone off my balance.

    I paid for in app credits of $1000000 for $10 in the App Store. My balance has depleted accordingly but the app doesn't reflect the credit. There also isn't a way to check in the app. It is Tiger Woods 2012 from ea sports.

    I'm not sure I can make sense of this but without asking too many questions, you can resolve your question by contacting iTunes direct.
    Apple - Support - iTunes - Contact Us
    But they will be wondering about the reference to hacking and you feeling bad about getting something for free.
    Best step in my view is to make sure you don't get similarly involved in future.  You must know roughly what you were doing.   Then writie it off to a not to be repeated experience.

  • Why doesn't Flash have the option to publish to .flv?

    Why doesn't Flash or Adobe Media Encoder have the option to publish or covert .swf to .flv?
    Any suggestions on free .swf to .flv coverters?

    Thanks, kowboy.  I've just seen a few of those video conversion tools that specifically advertise .swf to .flv conversion.  They may degrade the quality and make certain features not work just like when you convert to .avi.  I was wondering if anyone has had any experience with any of those tools.
    I know this is a fairly odd situation.  Both myself and the other flash developer advised that they not use Flash to create 5 min plus videos and then wrap them in .flv flash players.

  • Why doesn't iTunes allow the podcasts to be downloaded by Release Date?

    I am using iTunes 11.0.2 (25) on my iMac (2010).  I am curious why iTunes does not allow the podcasts to be downloaded by Release Date?
    It will help me so much when I create the playlists by Release Date especially when I download the podcasts after their releases.
    Please advice and thank you.

    I find that this setting does remove any podcasts that I have already listened to at the time of the next refresh, provided that I have not told iTunes not to delete the podcast (right-click, Do Not Auto Delete). If you need it gone right away, try hitting the refresh button.
    MacBook Pro   Mac OS X (10.4.9)  

  • Why can't I use the clone tool?

    I keep getting the message that says "cannot use the clone stamp because the are to clone has not been defined."  I option click and I keep getting this message.  All the other tools work, including the pattern clone.

    Could you please post a screenshot with the pertinent Panels visible?
    When you press the alt-button does the cursor change?

  • Why doesn't mail print the .ics details shown on screen?

    I have colleagues using outlook and I of course use mail.
    When they send me meeting requests I get a .ics file I can use in iCal.
    The details of the .ics file (e.g. agenda) displays OK in mail.
    But when I want to print the mail to take to the meeting, it just shows the .ics icon, nothing else.
    Browsing the discussions, this was a problem back in 2007 in Tiger, but fixed there and subsequently.
    Why have we got this "feature" back now in Lion? (The old fix - print from Get Info in iCal - doesn't work in Lion.  Must be the cheap leather finish)
    Any cures?

    Have you tried using the '''Print''' item at the bottom if that eBay page? <br />
    Or is that what you are using?
    Overall it isn't unusual for "print" to be a bit different than what shows on the "screen", that page may use @media for "screen" and for "print". The '''Print''' item on that page could be the difference, or the web browser might be following that code is you used the '''Print ''menu item or button''''' in Firefox. <br />
    http://www.w3.org/TR/CSS2/media.html#media-types
    Typically, the '''@print''' CSS code is used to hide navigation menu's ''(can't "navigate" to a different web page from a sheet of paper)'' and maybe advertisements ''(can't "click" on an ad that is on paper)'' from being printed out so that only the text of an article is printed to paper.
    Basically, it's probably not a fault with Firefox, but rather Firefox following the commands on the page put there by the person who authored that page, or a standard CSS "style sheet" used by eBay.

  • Why doesn't FF make the latest Update compatible with a Power PC G4?

    I've got a Power PC G4 Mac, which apparently doesn't meet the System Requirements for the latest Update of Firefox: why not? In this Economy, I'm sure there are a lot of people like me still running Power PC's, yet now I can't even "suggest" to FF that they include us in the Update, because I "don't have the latest version"! I run my whole Office from my Mac, so it's still pretty darn good. What's with the disrespect?

    Firefox 4 and later require at least OS X 10.5 and an Intel Mac.
    *http://www.mozilla.org/firefox/10.0/system-requirements/
    For an unofficial Firefox 10 compatible version (TenFourFox) that runs on PowerPC Macs with OS X 10.4.11 or OS X 10.5.8 you can look at:
    *http://www.floodgap.com/software/tenfourfox/
    *http://www.macupdate.com/app/mac/37761/tenfourfox
    *http://code.google.com/p/tenfourfox/wiki/ReleaseNotes100
    *http://code.google.com/p/tenfourfox/wiki/PluginsNoLongerSupported
    *http://code.google.com/p/tenfourfox/wiki/AAATheFAQ
    Firefox 3.6.26 has been released, so you can update to that version.<br />
    Latest Firefox 3.6.x (Mac OS X 10.4 and later) can be found here:
    * http://www.mozilla.com/en-US/firefox/all-older.html

  • Why doesn't applecare cover the bottom case pads?

    Hi, this is a question I should have just asked at my appointment, but I was in a real rush to get to work, so I just accepted it and went on, but anyway:
    One of the little black pads the macbook pro rests on to avoid heat collection fell off my computer (no physical damage, or anything else), and it turns out the entire bottom case has to be replaced to fix that.  It's a little crazy, but the Genius just said newer models have to have the bottom replaced to avoid internal damage from re-gluing.  Not only that, but the warranty doesn't cover it (under any circumstances, was the implication). 
    It's an annoying $40 dollars to spend, but really I'm just a little curious as to why this would be, when they're pretty generous if you have Applecare in most other cases.

    Hi, and welcome to Apple Support Communities.
    Did you read the Terms of Use when you signed up here?
    (Yeah. Who reads those, right?)
    You need to take a look:
    https://discussions.apple.com/static/apple/tutorial/tou.html
    Section 2.2.2:
    SubmissionsStay on topic. Apple Support Communities is here to help people use Apple products and technologies more effectively. Unless otherwise noted, do not add Submissions about nontechnical topics, including:
    Speculations or rumors about unannounced products.
    Discussions of Apple policies or procedures or speculation on Apple decisions.
    We are users here, like yourself, so speculating on why Apple decided a certain thing a certain way is above our pay grade.
    If it were mine, I might ask for a supervisor's opinion on the matter.
    I also might consider myself lucky that it was $40 and not $240.

  • Why doesn't this replace the XML in my file?

    I am trying to write some code that replaces some XML in a file. The first part works (opening the file, locating the XML, replacing it). When I save the file, it contains the original XML not the modified XML.
    I used the Get XML method to retrieve the text I wanted to change, Setting the Value property of the node doesn't seem to work but I don't know what else to try - I need the equivalent of a 'Set XML' invoke node but I haven't found it.
    Any ideas? Am I even close?
    (I'm new to XML and manipulating it in LabVIEW and I'm glazing over now so ideas which don't involve reading another 20 documents would be really appreciated, thank you  )
    Attachments:
    Replace XML in file snippet.png ‏70 KB

    Well, Darin was first and I had same idea with XPath... So I'll post it anyway, just for the sake of effort taken
    Actually, using XPath does not require "20 documents", it is quite easy, so I'd recommend you to take a look at it if you're going to use XML.

  • Why doesn't Verizon approve the Nexus 5?

    I just got done chatting with Verizon support.  I was trying to decide whether to buy the Nexus 5 but they said it hasn't been approved for the Verizon network.  Is there a technical reason for this or just a "business decision" (aka disagreement with Google) or both?  I've read endless blog posts and comments but am interested to know the official reason.  What would happen if I try to activate the phone via MyVerizon?

    Maybe it doesn't support it because Verizon said no thanks.  did you hear the debacle on the Nexus 7 tablet that Verizon chose not to sell after Google announced it would be available on Verizon?  Maybe this is more about Verizon making secret deals with Apple to help protect it's sales.  Really, the only distinction from Apple to Android, is that if it's not a Nexus device, it gets updates filtered thru the device manufacturer and the carrier.  But Apple doesn't get this filter, and neither does Nexus devices, so it stands to reason.  Remember VZ Navigator on non-Nexus devices?  Really Verizon, if Apple can't make a better map navigation tool (remember the debacle with iPhone 5 and Google maps?) then why do you think you can do better than Google?  some opf my money I pay to Verizon goes to them developing stupid apps like VZ Navigator that don't even get used and just suck up space and resources on my phone!  Kicking Verizon to the curb and heading to T-Mobile.  The more customers that switch, the better the network will get on T-Mobile.  Then Verizon will change it's tune when it's not number one.

  • Logic asks for my serial number every time I reboot the computer.  Anyone know what gives?  I restored the program after a hard drive crash and now I need to enter the serial number every time.  Why doesn't it remember the code?

    After a computer crash I had to reinstall the whole system using Migration Assistant.  The User ID is NOT the same as the original computer.  And now every time I reboot the computer and load Logic the program asks me to enter my Serial Number with a "Licensing" window. Why can't the copy protection see that I have already done this?  Am I missing some Pref file, or is it in the wrong location?  The program works fine once I enter in the number and insert my Logic XSKey (from an older update).  Thanks.

    Hi!
    Do you run automap 4.8/4.9? If so, then the chance is that automap is the culprit for slow undos/redos on LPX 10.1. Delete the Novation controller in the LPX controller surfaces. You find it under preferences/controller surfaces. If that is the solution for you, then uninstall automap. You find the uninstaller under applications-automap.
    Good luck!

  • Why doesn't Spotlight reveal searched item if it is inside a Desktop folder

    Scvenario:
    I created a folder on Desktop called Test into which I placed two Word documents and one pdf document.
    Then I went to Spotlight and had it search for these documents.
    Spotlight listed every occurrence of these items EXCEPT their presence in the Desktop folder.
    In seven years of Mac ownership, I never knew this.
    So if I have several folders on the Desktop into which I have put a number of items, there appears no way to locate a specific item via Spotlight but only by opening each folder separately and looking into it.
    Surely this can't be right.
    Thanks

    I have some new information:
    I created a folder on the Desktop called XXXXXXXX
    Into this I dropped a Word document and gave it a name that is not present anywhere in the computer.
    Then I went to Spotlight. It finds the document in Word but makes no mention of the XXXXXXXX file.
    HOWEVER, when I click "Get Info", it shows the document to be in folder XXXXXXXX
    I have a friend whom I am trying to get to clean up his Desktop on which resides perhaps sixty files/folders. I want him to put these items into a couple of folders. He maintains he will not be able to find the files. He knows very little about computers, and I am trying to make this as easy as possible.
    But Spotlight will not pinpoint a file inside a Desktop folder unless we click Get Info.
    Why???

Maybe you are looking for