I want to make this class immutable. How to optimize performance?

Hi,
I designed an immutable class for other people to use. And I'm wondering if there's any way to optimize it for performance.
ie.
class MyImmutableList
  final List myList;
  public MyImmutableList(List list)
    myList = list;
  public MyImmutableList append(Item item)
    List copy = myList.copy();
    copy.append(item);
    return new MyImmutableList(copy);
}But I find that many times, other people use the class like this:
someList = someList.append(item);So in a case like this, append() is unnecessarily making a copy of the list.
Is there anyway to optimize this?
Thanks
-Cuppo
Edited by: CuppoJava on 20-Jul-2008 5:44 AM
Edited by: CuppoJava on 20-Jul-2008 5:44 AM

DrClap wrote:
Well, of course, what else should they do when the method returns an ImmutableList?
What I would do with that append() method would be to remove it from the API entirely. The class is supposed to be immutable? Then it doesn't need an append() method. Unless, of course, the append() method isn't meant to change the state of the object, which seems a bit, let's say, unintuitive. Returning a copy of the list with the object appended then wouldn't change the state of the object, but it would return a new object. Which in fact is what the code does. But why? I'm like those other people, I would do that too. I don't understand the purpose of the method.The Defence calls java.math.BigDecimal
>
BigDecimal, would it be fair to say, you are an immutable class?
It would.
Would it also be true to say that you have an add() method?
I do
And would it be fair to say that adding could be construed as a mutating operation?
I suppose so
And what does this method do, given that you claim to be immutable?
It returns a new object which is the result of the add() operation
Thankyou

Similar Messages

  • I want to upgrade iPhoto from 7.1.5 to 9.2.3 but my computer says I must have 9 1 to make this upgrade. How do I get 9.1?

    I want to upgrade iPhoto from 7.1.5 to 9.2.3 but my computer says I must have 9>1 to make this upgrade. How do I get 9.1?

    Buy iPhoto from the Mac App Store.
    (90036)

  • I want to make gImage Class extends Image and use Graphics2D

    Sorry, my english short...
    I want to make gImage Class extends Image and use Graphics2D
    I trying to do...
    make class gImage..
    extends Image class. (Inheritance)
    but Image class is abstract class..
    And I want to use gImage class same as Image class.
    I can't use constructor... because by Abstract calss...
    How do i?
    Help me.. plz...
    And I want to use Graphics2D at Applet Game, But not use Java JDK Plug-in...
    No Way?

    You need to use BufferedImage with 2D or RenderedImage with JAI.
    BufferedImage effectivley extends an Image so you can
    draw it to screen in paintCOmponent.
    I use an Extended JPanel to draw an image in a Panel with this.
    MArk

  • HT201364 Hello ! i have a question about my Hard's Disc storage space. I have Mac book Pro 11" Retina with hard disk 120 GB . I want to make this update but its impossible because of no free space. And now i want to ask. Its 120 GB full space but i dont k

    Hello ! i have a question about my Hard's Disc storage space. I have Mac book Pro 11" Retina with hard disk 120 GB . I want to make this update but its impossible because of no free space. And now i want to ask. Its 120 GB full space but i dont know how.  It tells me lets say i have 30 GB movies but i dont have anything ! Can you help me with any way ? If i can do something to see what movies let's say means !  
    Thank you !!

    Hope this helps.
    1. Empty Trash.
        http://support.apple.com/kb/PH10677
    2. Start up in Safe Mode
        http://support.apple.com/kb/PH11212
    3. Delete "Recovered Messages", if any.
        Hold the option key down and click "Go" menu in the Finder menu bar.
        Select "Library" from the dropdown.
        Library > Mail > V2 > Mailboxes
        Delete "Recovered Messages", if any.
        Empty Trash. Restart.
    4. Repair Disk
        Steps 1 through 7
        http://support.apple.com/kb/PH5836
    5. Disk space / Time Machine ?/ Local Snapshots
       http://support.apple.com/kb/ht4878
    6. Re-index Macintosh HD
       System Preferences > Spotlight > Privacy
       http://support.apple.com/kb/ht2409
    If this does not help, you have to buy an external HD and move your movies photos.etc to
    the external HD.

  • How to make a class immutable?

    I hav attend the interview where they ask this question.
    I know little bit is Make the class final and declare all variables as static final .
    Can any Help me.
    This question

    Thi is just my opinion;
    An immutable object is an object that once created, it's values can no longer be changed.
    Thus an immutable object could be an object that allows it's values to be changed only when created with the use of the constructor, and only has get methods to retrieve those values (no set methods).
    @Peetzore
    Defining them as final is something I never did, however it makes sense :) and will start doing so as well
    Regards,
    Sim085

  • I want to make a DVD on how to use Garage band and sell them. Do I need apple's permission to do this?

    If I want to write a book on how to make great music in Garage Band and sell the book do I need permisison. I also thought about making video tutorials on the same subject. Again do I need permission to do this?

    This is a user forum, and certainly not a legal forum. 
    Legal systems and requirements vary by geography. 
    If you have a legal- or trademark-related question, you'll want to check directly with your own lawyer, and potentially with the folks at Apple Legal.

  • After upgrading to Yosemite, my MacBook Pro now requires me to enter a password whenever I start up my computer. I want to eliminate this step. How?

    After upgrading to Yosemite, my MacBook Pro now requires me to enter a password whenever I start up my computer. I want to eliminate this step and to go back to the ability to reboot and begin using without a login.  How do I accomplish this?

    Hightlight Login Option.  This will bring up the window showing Automatic login.
    Please post a pic of your window if Automatic login is missing.  Make sure your personal info is not showing.

  • An OLD INACTIVE email address, asking for a password, continues to show up to play certain selections in my iTunes Music Library.  I want to REMOVE this old email, HOW DO I REMOVE IT!!  All attempts to remove it have failed!

    An OLD INACTIVE email address, asking for a password, continues to show up to play certain selections in my iTunes Music Library.  I want to REMOVE this old email address, HOW DO I REMOVE IT!!  All attempts to remove it have failed!

    Yes, if you change your Apple ID to your new email address. You don't have to. Under those sort of situations you can speak to Apple about transferring your purchased items to the new Apple ID, and see if they will help you.
    You don't lose access to your older purchased items, you simply cannot update or re-download them or, in some cases, use them without providing the old Apple ID and password. All purchased items are permanently tied to the Apple ID used at time of purchase.

  • I already bought mac book pro last year but it can't view windows just like mac pro for education. I want to make like it. How?

    I already bought mac book pro last year but it can't view windows just like mac pro for education. I want to make like mac pro for education How?

    First, if you have a MACBOOK PRO (a laptop), you should post in that forum. MAC PRO (desktop) and Macbook Pro are different things, so when you use those terms interchangeably, it's impossible to know what you're talking about.
    Second, even guessing that you have a laptop, I still have no idea what your question means. Are you trying to load Microsoft Windows on it? Every Mac can run Windows using either Boot Camp or Parallels/Fusion/VMWare solutions. Please explain in more detail what you're trying to do, and we'll try to help. But post in the Macbook Pro forum if you're talking about a laptop.
    Matt

  • I want to make this button bar

    hi there,
    anyone know how to make this website button bar?
    http://www.grouplotus.com/grp/.
    i tried to find tutorial at flashkit.com but can't find
    it......
    pls help help~~
    many thanks

    im not giving a full blown tutorial.
    but you do that by having the main buttons, and making
    onRollover events, that trigger that highlight movieclip to follow
    the mouse, and snap to the nearest buttons, and that movieclip has
    that top menu attached, that will show up and ease in on the
    Rollover. it will take you a while to make it. but yea thats how.
    its all actionsctipt tweens.

  • I want to make a complaint but how? Cant find an address to write to?

    I'm extremly annoyed: purchased a 13" mac book pro on 13/11/13 for my teenage sons birthday and christmas present, on 29/11/13 he couldnt start the mac book up. We took it to our nearest apple store & saw an apple genius, we left it with them for 2 hours. On our return we thought it had been fixed, however when we got home my son done what the genius told him, again still not fixed. We made 2 further calls to the store, still cant fix it! Final straw, i took it back to the apple store on 5/12/13, left it there overnight, they called today and said it needs a new logi board which is going to cost us £409!! So we paid £999 just 13 months ago & they now are saying we need to pay another 40% of the original purchase price to get the mac book back to working order. Am truly so angry with Apple & want to take this further... After all i thought Apple products were built to last ?....!!!

    As you mention £ I assume you are in the UK.
    Apple products and EU Statutory Warranty
    http://www.apple.com/uk/legal/statutory-warranty/

  • I click on a link and It won't automatically load the page; I want to change this setting. HOW??

    Hi,
    When I ope my mail in gmail. I click on a link to open a new tab and show me what ever it is I've just clicked on....Firefox won't just load the page like it did before I upgraded to this latest version. It says: Firefox prevented this page from automatically redirecting to another page. and asks me to allow. I allow.
    How can I tell firefox that if I have clicked on a link, I want to view it. That seems intuitive enough. I don't want to allow every time. I do this all day~
    Thanks,
    Melissa

    See:
    *Firefox > Options/Preferences > Advanced > General : Accessibility : [ ] "Warn me when web sites try to redirect or reload the page"
    The setting in "Options > Advanced > General" is meant as an accessibility feature, as you can see by the label of that section, so that people with disabilities or people who use screen readers do not get confused and is not meant as a safety protection to stop redirecting.
    See also:
    *https://support.mozilla.org/kb/settings-network-updates-and-encryption#w_general-tab
    *http://kb.mozillazine.org/accessibility.blockautorefresh
    *http://kb.mozillazine.org/Accessibility_features_of_Firefox

  • I want the create this report but how to???????????????????????????????

    I'm created my oracle10g database with oracle XE databaselink and create view on XE for my customer report. And then create simple report. Everythings ok but when I push the run report report came with all data but I don't want to when push the run button. I want to run and then write customer ID and then push the GO button and then only came to 1 data or info. Can I do this and how???
    Help me please, I'm working about this a few days but I can't do anything :(((
    This is so important for me, help me please...

    Hi,
    OK
    Assuming you are using Page 1 for the report, do the following:
    1 - Create a new HTML Region called "Search" and put this above your report on the page layout
    2 - Add a normal Text item called "P1_CUSTOMER_ID" into the new region - this will be where your user enters in the CUSTOMER_ID value that they want the report to filter by
    3 - Add a Hidden Item called "P1_DISPLAY" into the new region. Set the Default Value for this item to N. If this is 'Y', the report will be shown - if this is 'N' the report is hidden
    4 - Add a button called "P1_SEARCH" into the new region
    5 - Add a button called "P1_RESET" into the new region
    6 - Update your SQL statement to include a WHERE clause:
    SELECT ....
    FROM ....
    WHERE CUSTOMER_ID = :P1_CUSTOMER_ID
    (you may have to do TO_NUMBER(:P1_CUSTOMER_ID) if your CUSTOMER_ID field is numeric)
    7 - Add a branch to the page that branches to Page 1 and sets P1_DISPLAY to Y. Set this branch to be run only when the P1_SEARCH button is clicked
    8 - Add another branch to the page that branches to Page 1 and sets P1_DISPLAY to N. Ensure that this has a higher sequence number than the first branch
    9 - Finally, add a Conditional Display to the report region. Set the Condition Type to "Value of Item in Expression 1 = Expression 2". Enter P1_DISPLAY into Expression 1 and Y into Expression 2
    Regards
    Andy

  • HT2693 Pls Pls Pls Help me my iphone is stucked on conect to itunes its not working , unresponsive,i dont know what happen with my iphone my friends telling me that may be your iphone no jailbreak , but i dont want to make this happen i dont need it.

    Pls Pls Help me >>> i bougt my iphone just 1 years ago,i dont know what happend with my iphone,its unresponsive,showing only connect to itunes ,and when i tried to restore after that messgae came on my laptop that Error 21, could not restore ,,, my friends telling me that may be somebody trying to jailbreak your mobil so this was the reason can happen but i dont want any kind of jailbreak i want my iphone back to my work plss help me i m very poor person i cant efford to buy again this phone

    Anyone have any suggestions? or is everyone else just as clueless as me !

  • HT201068 I want to ignore this update.  How do I remove it from my active list on the App Store app?

    Can I remove this update from the active list on the computer?  I don't want it active as I may by mistake install this unwanted update

    You can only hide some updates (i believe only OS X updates).  You can do so by right clicking or control clicking in the blank area around the description or title of the update in the App Store list and choosing hide update.  If you'd like to restore them, choose the Store option from the menu bar and then "show all software updates"
    you can alternatively use the Terminal to "ignore" updates and reset "ignored updates".  For more information on that open Terminal and type:
    softwareupdate info

Maybe you are looking for