Generics and clone().

I am trying to do
ArrayList<Integer> tempList = (ArrayList <Integer>) list.clone();but I get the unchecked warning. list is defined as ArrayList<Integer> list.
Basically, I am trying to cast the clone of list so that list remains unchanged by my method, so I am creating a templist using the clone. I am confused with respect to how to go about doing this cast using generics.
Thanks in advance.

This version gives the warning:
public class Test {
    public static void main(String[] arguments) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        ArrayList<Integer> clone = (ArrayList<Integer>)list.clone();
}However, Drake_Dun is right, you probably want to copy the
list rather than cloning it. If you insist on using clone without a
warning, you loose the type information:
public class Test {
    public static void main(String[] arguments) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        ArrayList<?> clone = (ArrayList<?>)list.clone();
}

Similar Messages

  • Casting, generics and unchecked expressions

    Hi
    I'm trying to access a vector of Recommendations held by a Person object, but I don't want to allow direct access to the vector, just the information contained in it
    public Vector<Recommendation> getRecommendations() {
         return((Vector<Recommendation>)recList.clone());
    }The trouble I'm having is that I have to cast the recList.clone() as a Vector<Recommendation> to return a compatible type.
    When I do this, the source compiles with a warning: unchecked cast.
    Could someone explain an unchecked cast and give me a pointer to solving this please? I've not managed to find anything about combining generics and clones in my books. Is there another way of returning a copy of the vector? All I want to do is make the objects in the vector available for viewing, via processing in a servlet, to a jsp.
    Thanks in advance

    YoGee wrote:
    What you are exposing is a Vector with a reference to a clone of the internal data array, you are not cloning the elements in that data array. So basically if you modify an element in one Vector chances are it will be reflected in the other (assuming the element is mutable).Thanks for the reply.
    I should have said that what I want to achieve is:
    make the Vector<Recommendation>recList contents available for viewing, but not expose the objects so that they are able to be changed - so what I have done is not good!
    after some thought, what I really want is this:
    If what you actually want to achieve is a deep clone (i.e. clone the elements in the internal data array) you need to do it yourself by looping through the Vector and cloning each element in it (assuming the elements implement clone properly)so thanks for the help!

  • I need to synch my iphone, ipod touch and classic to a Mac that I have and 2 I am about to buy. I have legally paid for all my music. If I use migration on my new Macs and clone the original, can I use my iAppliances on all 3 Macs?

    I need to synch my iphone, ipod touch and classic to a Mac that I have and 2 I am about to buy. I have legally paid for all my music. If I use migration on my new Macs and clone the original, can I use my iAppliances on all 3 Macs?

    Yes.
    You can authorize up to 5 computers to play itunes music ( pre-itunes plus).  There is no limit on itunes plus ( all itunes music for the past several years) and imported music.
    You can sync as many ipods/ipads/iphones as you like to each of your computers.

  • Generic and Inheritance, how to use them together?

    Hi guys, I am trynig to design some components, and they will use both Generics and Inheritance.
    Basically I have a class
    public class GModel <C>{
        protected C data;
        public C getData(){return data;}
    }//And its subclass
    public class ABCModel <C> extends GModel{
    }//On my guess, when I do
    ABCModel abcModel = new ABCModel<MyObject>();The data attribute should be from MyObject type, is it right?
    So, usign the netbeans when I do
    MyObject obj = abcModel.getData();I should not use any casting, since the generics would tell that return object from getDta would be the MyObject.
    Is this right? If yes; did someone try to do that on netbeans?
    Thanks and Regards

    public class GModel <C>{
    public class ABCModel <C> extends GModel{public class ABCModel <C> extends GModel<C>{
    ABCModel abcModel = new ABCModel<MyObject>();ABCModel<MyObject> abcModel = new ABCModel<MyObject>();

  • CS2 Eye dropper and clone tool not picking up correct colour from image.

    Hello everyone, Can anyone help me please. I have an iMac with 0SX 10.4.4.
    Plenty of Ram and hard drive space. In using CS2 the eyedropper and clone tools will not pick up the exact same colour from the image that I require. It is always lighter in shade and has on occasion been white. Any help in solving this problem will be much appreciated.
    Yours in anticipation, Geoff Walter.

    >The eyedropper is picking-up the color as rendered in RGB on your Monitor...
    Really? Not from the pixels in the file? So the same pixels are reported with different values depending on monitor setup? This is about how the eyedropper reports pixel values, not about how they are rendered to the screen, is that correct?
    Just to be sure here, this is so even with the eyedropper set to point sample?
    Al
    Edit: Or do you mean that this is a known problem with 0SX 10.4.4. and Photoshop, in which the values are picked up from the monitor and not from the file data?

  • No of physical reads of buffers from disk on PROD and Clone has huge differ

    Please help !
    I am having a problem interpreting a tkprof report.
    I am executing the same statement below in PROD and Clone of PROD.
    What I do not understand why the tkprof report shows huge difference in disk reads for same executions from PROD and Clone of PROD. I.e. first execution disk reads = 757187 , second = 6.
    I expected to see Similar disk reads in the second execution also.The data it fetches is same in both the Instances.
    Statment
    SELECT NVL(SUM(RG_OTH.DEBIT),0),NVL(SUM(RG_OTH.CREDIT),0)
    FROM
    JA_IN_PLA PLA,JAI_RG_OTHERS RG_OTH,HR_ALL_ORGANIZATION_UNITS HOU,
    HR_LOCATIONS LOC,JA_IN_HR_ORGANIZATION_UNITS HR_ORG WHERE 1 = 1 AND
    PLA.ORGANIZATION_ID = :b1 AND TRUNC(PLA.CREATION_DATE) >= :b2 AND
    TRUNC(PLA.CREATION_DATE) <= :b3 AND HOU.ORGANIZATION_ID =
    PLA.ORGANIZATION_ID AND LOC.LOCATION_ID = PLA.LOCATION_ID AND
    HR_ORG.ORGANIZATION_ID = PLA.ORGANIZATION_ID AND HR_ORG.LOCATION_ID =
    PLA.LOCATION_ID AND TRANSACTION_ID = 19 AND INVENTORY_ITEM_ID != 0 AND
    NVL(ROUNDING_ID,1) != -1 AND RG_OTH.SOURCE_REGISTER_ID = PLA.REGISTER_ID
    AND RG_OTH.SOURCE_REGISTER = 'PLA' AND RG_OTH.TAX_TYPE IN (
    'EXCISE_EDUCATION_CESS' )
    Tkproff from PROD.
    call count cpu elapsed disk query current rows
    Parse 1 0.01 0.01 0 0 0 0
    Execute 1 0.04 0.03 0 0 0 0
    Fetch 1 973.41 1724.95 757187 789442 0 1
    total 3 973.46 1725.01 757187 789442 0 1
    Tkproff from CLONE of PROD.
    call count cpu elapsed disk query current rows
    Parse 1 0.06 0.05 1 789 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 1 0.73 0.72 6 30594 0 1
    total 3 0.79 0.78 7 31383 0 1

    wins wrote:
    SELECT NVL(SUM(RG_OTH.DEBIT),0),NVL(SUM(RG_OTH.CREDIT),0)  
    FROM
    JA_IN_PLA PLA,JAI_RG_OTHERS RG_OTH,HR_ALL_ORGANIZATION_UNITS HOU,
    HR_LOCATIONS LOC,JA_IN_HR_ORGANIZATION_UNITS HR_ORG  WHERE 1 = 1  AND
    PLA.ORGANIZATION_ID = :b1  AND TRUNC(PLA.CREATION_DATE) >= :b2  AND
    TRUNC(PLA.CREATION_DATE) <= :b3  AND HOU.ORGANIZATION_ID =
    PLA.ORGANIZATION_ID  AND LOC.LOCATION_ID = PLA.LOCATION_ID  AND
    HR_ORG.ORGANIZATION_ID = PLA.ORGANIZATION_ID  AND HR_ORG.LOCATION_ID =
    PLA.LOCATION_ID  AND TRANSACTION_ID = 19  AND INVENTORY_ITEM_ID != 0  AND
    NVL(ROUNDING_ID,1) != -1  AND RG_OTH.SOURCE_REGISTER_ID = PLA.REGISTER_ID 
    AND RG_OTH.SOURCE_REGISTER = 'PLA'  AND RG_OTH.TAX_TYPE IN (
    'EXCISE_EDUCATION_CESS'  )
    Tkproff from PROD.
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.01       0.01          0          0          0           0
    Execute      1      0.04       0.03          0          0          0           0
    Fetch        1    973.41    1724.95     757187     789442          0           1
    total        3    973.46    1725.01     757187     789442          0           1
    Tkproff from CLONE of PROD.
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.06       0.05          1        789          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.73       0.72          6      30594          0           1
    total        3      0.79       0.78          7      31383          0           1
    As others have pointed out, this looks like a change in execution plan. At a guess, the PROD database is doing a tablescan somewhere (physical reads is approximately equal to logical reads is a pointer).
    There are many reasons why this could happen, continuing with the guesswork - we note that the statement was re-optimised (hard parsed) in the clone, but used an existing cursor in production (logical I/O = 0 in prod, 789 in clone). So the plan you got in the clone was the one that Oracle thought best for the inputs you had supplied. The plan in prod could have been produced as the response to a completely different set of input; since you have two bind variables applied to a range based predicated and one bind variable with equality it's possible that you have a histogram that makes a difference on the equality column, alternatively the range of dates used to generate the original plan was very different from the range used in the test.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    Author: <b><em>Oracle Core</em></b>

  • Difference bw the data staging of generic and appli specefic data sources

    Hi,
       Can anyone tell the difference between data staging of generic and appl specific data sources. Like we know that LO data stage in queued delta, update queue and BW delta queue, i want to know actually where the generic data stages before it is loaded into BW.
    Thanks.

    Generic data sources are based on either a DB table/view, a function module or an ABAP query. So normally the data stages in the corresponding DB tables or you calculate it at extraction time. There is no update queue like in LO.
    Best regards
       Dirk

  • Generic and Flat file extraction

    Hi experts
    can any body send the Real time scenario for Generic and flat file extraction with examples.
    Thanks and regrds,
    satya

    Hi,
    Generic extraction is an extraction where you create a Generic DS and based upon this you would be extracting the data from R/3, which means you would have an source system to extract the generic data from the generic data source.
    Flact file extraction is an extraction where you need not have to connect to source
    system, in this case you source system would be PC, here you would be designing an infosource based up on the fields/columns of your flat file and mapping the corresponding the infoojects to it.. and update rules..
    and you would be loading/extracting the data from the file as a source..
    These two things are different in nature and usage..
    Hope this helps..
    assign points if useful..
    cheers,
    Pattan.

  • Using generics and J2SE together with JSF

    Hi
    Has anybody experience with using JSF together with J2SE 1.5? Especially generics? I would like to use generics and other improvements from J2SE in the model objects.
    Thnaks in advance ... Rick

    JSF 1.1 is specified for J2SE 5, and the new specification (JSF 1.2 and JSP 2.1) does not include generics.
    If you are talking in terms of ValueBindings or MethodBindings, there really isn't any point since the implementation could only make the cast for you; and it would still not be able to garuantee type safety (the only reason to use generics).
    That's not to say you couldn't use generics in your own development, but I don't think you will see generics incorporated into the specification any time soon.
    Jacob Hookom (JSR-252 EG)

  • Cloning a ZFS rooted zone does a copy rather than snapshot and clone?

    Solaris 10 05/08 and 10/08 on SPARC
    When I clone an existing zone that is stored on a ZFS filesystem the system creates a copy rather than take a ZFS snapshot and clone as the documentation suggests;
    Using ZFS to Clone Non-Global Zones and Other Enhancements
    Solaris 10 6/06 Release: When the source zonepath and the target zonepath both reside on ZFS and are in the same pool,
    zoneadm clone now automatically uses the ZFS clone feature to clone a zone. This enhancement means that zoneadm
    clone will take a ZFS snapshot of the source zonepath and set up the target zonepathCurrently I have a ZFS root pool for the global zone, the boot environment is s10u6;
    rpool 10.4G 56.5G 94K /rpool
    rpool/ROOT 7.39G 56.5G 18K legacy
    rpool/ROOT/s10u6 7.39G 56.5G 6.57G /
    rpool/ROOT/s10u6/zones 844M 56.5G 27K /zones
    rpool/ROOT/s10u6/zones/moetutil 844M 56.5G 844M /zones/moetutil
    My first zone is called moetutil and is up and running. I create a new zone ready to clone the original one;
    -bash-3.00# zonecfg -z newzone 'create; set autoboot=true; set zonepath=/zones/newzone; add net; set address=192.168.0.10; set physical=ce0; end; verify; commit; exit'
    -bash-3.00# zoneadm list -vc
    ID NAME STATUS PATH BRAND IP
    0 global running / native shared
    - moetutil installed /zones/moetutil native shared
    - newzone configured /zones/newzone native shared
    Now I clone it;
    -bash-3.00# zoneadm -z newzone clone moetutil
    Cloning zonepath /zones/moetutil...
    I'm expecting to see;
    -bash-3.00# zoneadm -z newzone clone moetutil
    Cloning snapshot rpool/ROOT/s10u6/zones/moetutil@SUNWzone1
    Instead of copying, a ZFS clone has been created for this zone.
    What am I missing?
    Thanks
    Mark

    Hi Mark,
    Sorry, I don't have an answer but I'm seeing the exact same behavior - also with S10u6. Please let me know if you get an answer.
    Thanks!
    Dave

  • Healing and Clone tool

    When using the healing and clone toll, the brush frequently appears some other spot than where I am digitizing on the photo. I have tried new mouse, restarting, etc. If I open the same photo in elements 9, it works perfectly.

    Try re-setting the Preferences:  create a Desktop shortcut for the PSE Editor, then hold down the Ctrl+Alt+Shift keys while double-clicking on the shortcut to start the program.  Answer "Yes" to delete the Preferences.
    Ken

  • Photoshop elements...the tools (Paintbrush and cloner) no longer show their adjustable size when working. Only a tiny cross shows...is there a way to reset tools ??

    Photoshop elements...the tools (Paintbrush and cloner) no longer show their adjustable size when working. Only a tiny cross shows...is there a way to reset tools ??

    Please post Photoshop Elements related queries over at
    http://forums.adobe.com/community/photoshop_elements
    But a guess: caps lock?

  • TS1814 I can't seem to get the drivers downloaded on my windows laptop for my iphone 5s, the info is coming up generic and im getting a code 1.  Please help

    I can't seem to get the drivers downloaded on my windows laptop for my iphone 5s, the info is coming up generic and im getting a code 1.  Please help

    All necessary drivers are included in the iTunes install package.
    Please clarify exactly what the problem is.
    the info is coming up generic and im getting a code 1
    That's not very informative.

  • Generic and Variant Article in IDOC for EDI810

    Friends,
    i have an issue with processing the EDI810 with both generic and variant articles in the IDOC.
    i am testing the Idoc, but it fails. when i delete the generic article from the EDi810 and process the IDoc, the invoice is getting posted.
    is it that the vendor has to send otr EDI team has to suppress the generic articles and send only Variant areticle to SAP?
    how does it work
    Please help
    Regards

    In MM43 under Basic Data (uppermost portion), if you input a generic article, only the article will be displayed. but if you input a variant article, its generic article will be displayed on top of it...
    Its field name is RMMW1-VARNR. The generic article is RMMW1-MATNR.
    Message was edited by: Winnie Chan

  • Difference between Duplicate and Clone?

    I am making a copy of an existing symbol. Under the Edit menu they have Dulicate and Clone to accomplish this. What is the difference between the two? As far as I can tell, if I select clone, it puts a copy of the object directly on top of the selected object to copy. If I select duplicate it offets the copy so it's not directly on top of the original object to copy. Is that the only difference?

    I agree and it seems to me that there would be more of a difference between the two than just mere place of the symbol on screen.

Maybe you are looking for

  • Excel 2008, read-only file access from network volume

    Hi, Need some assistance please. I recently setup a Macbook Pro 17" 2.4Ghz (10.5.2) and did a migration from a Powerbook G4. Installed Office 2008. Excel will not open ANY files from a network volume without giving a read-only access error. Word is o

  • SharePoint 2010 and Office 2013 Can't edit documents

    Hello I have built a desktop image with Office 2013. I am receiving the following error when I click on a document in a SharePoint library and click "Edit in Microsoft Word" (the problem is not limited to Word): The document could not be opened for e

  • PP CC won't open a file saved on another computer

    A co-worker saved a PP CC edit and passed the file on to me to re-link the media and continue the edit, but my PP CC is telling me the file was created in a newer version of premiere. We checked both of our computers and they are both running the lat

  • ITunes post-upgrade: "Required files are missing"

    I just went through the process to install the latest upgrade, but there was some sort of problem with the installer. Rather than installing the upgrade, it apparently just deleted important files and then failed before replacing them. Now when I try

  • Texts in SO

    Hi Gurus, we have a requirement of displaying texts in sales order at the initial screen of the order entry so that it is easy for the user to enter the text. Please suggest ... Thanks in advance Regards, Arvind