How to add item to a List with a bounded wildcard

Hi,
Is there a way to add a subtype instance to a List with a bounded wildcard? For example, say I have an
abstract class called Car. Then I have 2 concrete subclasses--Ford and Toyota. Now say I have another
class that contains a prepopulated list and is wildcard bounded like this: List<? extends Car> carList. I
want to add a method where I pass in a Car subtype as a parameter and then add it into this list, e.g:
public void addCar(Car car) {
carList.add(car);
Trying this, I keep getting "cannot find symbol" compilation errors. When I went back to read the Generics
tutorial by Bracha, he mentions that explicitly adding a subtype, e.g. carList.add(new Ford()), can not be
done. But here I'm adding the "upper bound" of the wildcard, i.e. the Car type. Therefore there should be no
discrepancy between supertype and subtype an thus the carList.add(car) should be ok, IMO.
Am I misunderstanding something with this logic? Also, if carList.add(car) can not be done, then how can
I go about doing something similar which will allow me to add subtypes to a "generic" list?
Thanks in advanced!
-los

I get a compilation error expecting an Object instead of a Car. Of course you did. List<? super Car> is a list into which you can put cars -- and possibly other stuff. List<? extends Car> is a list out of which you can get cars (possibly of different makes).
Do you need a list that you can put cars in and get cars out? That's List<Car>
This isn't a linguistic problem you are having; this is a design problem. If you have a function that takes an argument which is a list that you can put any kind of car into and be sure of getting a car out of, it isn't reasonable to pass in a List<Ford> (because the function might put in a Chevy) or a List<Object> (but there might be motorcycles already in there). By the requirements you have, you need a List<Car> and nothing else.
Yes, you could use a cast, but all you are doing is circumventing the type system by saying "I know this List<Object> only has Cars in it."

Similar Messages

  • How do I create an unordered list with three items and link to id's

    How do I create an ordered list with three items and linl to id's on my page

    Thanks, I guess what I was really asking, Is there a n option in the insert menu or somewhere where Dreamweaver does it for you.
    I am not clear on what you are wanting DW to do for you?  Is it that you want it to insert a three item unordered list?  No - there's no such function.  You would need to click in Design view where you want the list to go, click on the bulleted list icon on the Property inspector, and then enter the three items separated by carriage returns.  Then you'd have to link each item specifically.
    To enter the named anchors to element ID values, CS5 has no way to do this.  You'd have to enter those links manually.

  • How to add Gap between dropdown List Items - ComboBox in MFC VC++

    How to add Gap between dropdown List Items - ComboBox in MFC VC++

    Did you tried SetItemHeight() inside your App .
    Thanks
    Rupesh Shukla

  • Object array - how to add items?

    Hello!
    I have little problem, how to add item to array, to get something like this:
    Object[][] someObject = {
    {"1", "2"},
    {"4","5"}
    };From this:
    Object[][] someObject = {
    {"1", "2"}
    };? Thanks in advance!

    Once you allocate an array like that, you can't
    resize it.
    Object[][] someObject = {
    {"1", "2"}
    };creates an array with size [1][2]. You can't makeit
    any larger. You can create a new Object[][]
    with the new size, copy the elements into the new
    array, then add your new objects in the newposition.
    or even better use arraylistExcept that he's using this for a JTable, so the best he could do is a Vector. Yuck. :)

  • How to add a video play list on palm pre

    Does anybody knows how to add a video play list in palm pre?
    I did try to add video in different folders but in the palm  device are loaded in the same playlist. Is there a way to organize video files?
    tks
    Post relates to: Pre p100ueu (O2)

    QuickTime requires player and plugins that most people don't have.  You'll reach a much wider audience if you use HTML5 <video> with mp4, webm and ogg files.
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>HTML5 with Video</title>
    <!--help for older IE browsers-->
    <!--[if lt IE 9]>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    </head>
    <style>
    video {
        max-width:100%;
        display:block;
        margin:0 auto;
    </style>
    <body>
    <h2>Use 3 File Types to support all browsers &amp; mobile devices:  MP4, WEBM and OGV.</h2>
    <h3>Online Video Converter
    http://video.online-convert.com/</h3>
    <!--begin video-->
    <video controls poster="Your_poster_image.jpg">
    <!--these are 6 sec sample videos for testing purposes. Replace sample-videos with your own files-->
    <source src="http://techslides.com/demos/sample-videos/small.webm" type="video/webm">
    <source src="http://techslides.com/demos/sample-videos/small.ogv" type="video/ogg">
    <source src="http://techslides.com/demos/sample-videos/small.mp4" type="video/mp4">
    If you're seeing this, you're using an
    outdated browser that doesn't support
    the video tag. </video>
    <!--end video-->
    </body>
    </html>
    Nancy O.

  • How to add admob in android app with dreamweaver

    how to add admob in android app with dreamweaver ?

    flash-air-admob-ane-for-ios-and-android - Admob Ane,a adobe native extention(ANE) for actionscript developer to add go…
    code and demo.but you need upgrade to flash cc.

  • SharePoint 2010 Rest API: How to add attachment to a list item via ListData.svc

    Hi
    I have set up a project using the REST API in c# Visual Studio 2010.
    I have added a service reference to the URL //site/_vti_bin/listdata.svc/
    I can query the list and get back data, but I can't retrieve the attachments.
    I can write data to the list, but I can't add attachments.
    Are there any examples of how to add or retrieve attachments using the REST API services.
    Thanks
    Mike

    Hi,                                                             
    If you want to work with list attachments using REST API, here are some links will show how to do this using Javascript:
    http://msdn.microsoft.com/en-us/library/office/dn292553.aspx#FileAttachments
    http://chuvash.eu/2013/02/20/rest-api-add-a-plain-text-file-as-an-attachment-to-a-list-item/
    http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2013/06/27/how-to-get-list-item-attachments-using-rest-and-javascript-in-sharepoint-2013.aspx
    Best regards
    Patrick Liang
    TechNet Community Support

  • How: can i get a specificated item from a list with more than 100.000 items

    Hi,
    i have a very large list and i got always an exception that the list has more than 5000 items and cant query!! But in the default list view i can see, order and filter all items. So how can i do this by c#?

    Hi,
    According to your description, my understanding is that you want to get a specific list item form a list which with more than 100000 items using C#.
    I suggest you can use CAML Query with some condition and set Row Limit to specify the number of items to return.
    Here is a detailed code demo for your reference:
    Client Object Model Access Large Lists/Overcome ListView Threshold while accessing large list
    Thanks
    Best Regards
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • How to add values in a List item using code

    Hi all,
    I want to populate a list item at run time with the values of my choice.
    im using this
    add_list_element('list34',1, 'Name','Smith');
    or
    add_list_element('list34',1, 'Name',:emp.txtname);
    where emp is my data block and txtname is a text field on this emp block.
    noen of them is working, whether i try adding a string or the value in a text item.
    please help.

    It gives any error or just does nothing?
    Have you tried making another simple form with just one block and one or two items?
    You can do this type of testing in these conditions.
    Which version of forms are you using?

  • DataGrid - Create at runtime - How to Add Items??

    I create a DataGrid at runtime and then and columns to it as need be. How Can I add items with the correct dataField if I don't if I don;t know this till runtime? In other word I'm having trouble constructing the Object to send to AddItem becase the dataField Name needs to be hard coded...
    Below does not work for me because if I have more than one column then I can seem to figure out out to create  ItemObjFinal dynnamically.
    var ItemObjFinal:Object = {ThisNameNeedsToBeDynamic: "text", ThisNameNeedsToBeDynamic: "value" };
    I also tried creating an array of Objects like this:
    var ItemObjFinal:Object = new Object;
    var obj:Object= dgc.dataField;
    ItemObjFinal [0] = {(obj.valueOf()):  dgc.headerText };
    ItemObjFinal [1] = {(obj.valueOf()):  dgc.headerText };
    =========================================================================================
                  ac.addItemAt(dgc, int(ac.length));
                  dataGrid_preview.columns = ac.toArray();
                  var obj:Object= dgc.dataField;
                  var ItemObjFinal:Object = {(obj.valueOf()):  dgc.headerText };
                  var obj2:Object= dgc.dataField;
                  var ItemObjFinal2:Object = {(obj2.valueOf()): dgc.headerText};
                  //K Now add it!
                  //IList(dataGrid_preview.dataProvider).removeAll();
                  IList(dataGrid_preview.dataProvider).addItemAt(ItemObjFinal,0);
                 //IList(dataGrid_preview.dataProvider).addItemAt(ItemObjFinal2,1);

    Ahh answered my own question:
                 ac.addItemAt(dgc, int(ac.length));
                  dataGrid_preview.columns = ac.toArray();
                  var ItemObjFinal:Object = new Object;
                  var ItemObjFinal2:Object = new Object;
                  for each(var col:DataGridColumn in ac)
                    ItemObjFinal[col.dataField] = col.headerText;
                    ItemObjFinal2[col.dataField] = col.headerText;
                  ItemObjFinal[dgc.dataField] = dgc.headerText;
                  ItemObjFinal2[dgc.dataField] = dgc.headerText;
                  //K Now add it!
                  if(IList(dataGrid_preview.dataProvider).length > 1)
                      IList(dataGrid_preview.dataProvider).removeItemAt(0);
                      IList(dataGrid_preview.dataProvider).removeItemAt(1);
                  IList(dataGrid_preview.dataProvider).addItemAt(ItemObjFinal,0);
                  IList(dataGrid_preview.dataProvider).addItemAt(ItemObjFinal2,1);
    This code may still need some tweaking as I get an RTE at  "IList(dataGrid_preview.dataProvider).removeItemAt(1);"   but at least I'm able to solve my original question. Thanks Alex!

  • How to add an SAP distribution list to transport?

    Hi All,
    I have created a shared distribution list in SAP using SO15. Can anyone suggest me how to add this list to a transport? or I need to create this in each environment.
    Please suggest on this issue.
    Thanks in advance
    Prady

    What does that mean? So I have to create it in each environment(i.e. Development/Quality/Production) explicitly. By no means I can transport this list then?
    Thanks for your quick response.
    With regards
    Prady

  • How to get items from a list that has more items than the List View Threshold?

    I'm using SharePoints object model and I'm trying to get all or a subset of the items from a SharePoint 2010 list which has many more items than the list view threshold (20,000+) using the SPList.GetItems() method. However no matter what I do the SPQueryThrottledException
    always seems to be thrown and I get no items back.
    I'm sorting based on the ID field, so it is indexed. I've tried setting the RowLimit property on the SPQuery object(had no effect). I tried specifying the RowLimit in the SPQuerys ViewXml property, but that still throws a throttle exception. I tried using the
    ContentIterator as defined here:http://msdn.microsoft.com/en-us/library/microsoft.office.server.utilities.contentiterator.aspx,
    but that still throws the query throttle exception. I tried specifying the RowLimit parameter in the ProcessListItems functions, as suggested by the first comment here:http://tomvangaever.be/blogv2/2011/05/contentiterator-very-large-lists/,
    but it still throws the query throttle exception. I tried using GetDataTable instead, still throws query throttle exception. I can't run this as admin, I can't raise the threshold limit, I can't raise the threshold limit temporarily, I can't override the lists
    throttling(i.e. list.EnableThrottling = false;), and I can't override the SPQuery(query.QueryThrottleMode = SPQueryThrottleOption.Override;). Does anyone know how to get items back in this situation or has anyone succesfully beaten the query throttle exception?
    Thanks.
    My Query:
    <OrderBy>
        <FieldRef Name='ID' Ascending='TRUE' />
    </OrderBy>
    <Where>
        <Geq><FieldRef Name='ID' /><Value Type='Counter'>0</Value></Geq>
    </Where>
    My ViewXml:
    <View>
        <Query>
            <OrderBy><FieldRef Name='ID' Ascending='TRUE' /></OrderBy>
            <Where>
                <Geq><FieldRef Name='ID' /><Value Type='Counter'>0</Value></Geq>
            </Where>
        </Query>
        <RowLimit>2000</RowLimit>
    </View>
    Thanks again.

    I was using code below to work with 700000+ items in the list.
    SPWeb oWebsite = SPContext.Current.Web;
    SPList oList = oWebsite.Lists["MyList"];
    SPQuery oQuery = new SPQuery();
    oQuery.RowLimit = 2000;
    int intIndex = 1;
    do
    SPListItemCollection collListItems = oList.GetItems(oQuery);
    foreach (SPListItem oListItem in collListItems)
    //do something oListItem["Title"].ToString()
    oQuery.ListItemCollectionPosition = collListItems.ListItemCollectionPosition;
    intIndex++;
    } while (oQuery.ListItemCollectionPosition != null);
    Oleg
    Hi Oleg, thanks for replying.
    The problem with the code you have is that your SPQuery object's QueryThrottleMode is set to default. If you run that code as a local admin no throttle limits will be applied, but if you're not admin you will still have the normal throttle limits. In my
    situation it won't be run as a local admin so the code you provided won't work. You can simulate my dilemma by setting the QuerryThrottleMode  property to SPQueryThrottleOption.Strict, and I'm sure you'll start to get SPQueryThrottledException's
    as well on that list of 700000+ items.
    Thanks anyway though

  • How to add data into a List box

    CS3 SDk:Windows<br /><br />Hi all,<br />I am trying to add  data into a basic List box in CS3??<br /><br />// .fr<br />GenericPanelWidget<br />     (<br />     // CControlView properties<br />     kInvalidWidgetID, // widget ID<br />     kPMRsrcID_None, // PMRsrc ID<br />     kBindNone, // frame binding<br />     Frame(0,0,250,90) // left, top, right, bottom<br />     kTrue, // visible<br />     kTrue, // enabled<br />     // GroupPanelAttributes properties<br />     "", // header widget ID<br />     { <br />     <br />     WidgetListBoxWidgetN<br />     (<br />     kWFPListBoxWidgetID, kSysListBoxPMRsrcId, // WidgetId,RsrcId<br />     kBindAll, // Frame binding<br />     Frame(0,0,250,90) // Frame<br />     kTrue, kTrue, // Visible, Enabled<br />     1,0, // List dimensions<br />     19, // Cell height<br />     1, // Border width<br />     kFalse,kTrue, // Has scroll bar (h,v)<br />     kTrue, // Multiselection<br />     kTrue, // List items can be reordered<br />     kTrue, // Draggable to new/delete buttons<br />     kFalse, // Drag/Dropable to other windows<br />     kTrue, // An item always has to be selected<br />     kFalse,// Don't notify on reselect<br />     kFalse, <br />     {               <br />     }     <br />                    <br />),<br />},<br />),<br /><br />//-------ID.h--------<br />DECLARE_PMID(kWidgetIDSpace, kWFPListBoxWidgetID, kWFPPrefix + 2)<br /><br />//observer.cpp-----------WFPDialogObserver::Update<br /><br />//get currently selected/active widget <br />WidgetID theSelectedWidget = controlView->GetWidgetID();<br /><br />// ist it the text edit field? <br />if (theSelectedWidget == kWFPInsertButtonWidgetID && theChange == kTrueStateMessage) <br />{ <br /><br />IControlView* listBox = panelControlData->FindWidget(kWFPListBoxWidgetID);<br /><br />InterfacePtr<IListControlData> listControlData(listBox, UseDefaultIID()); <br /><br />//Insert the string into listbox <br />PMString strText = dialogCtrl->GetTextControlData(kWFPTextEditBoxWidgetID); <br /><br />// obviously there can't be a translation for text entered by user <br />strText.SetTranslatable(kFalse);<br />listControlData->Add(strText,kWFPTextEditBoxWidgetID); <br />dialogCtrl->SetTextControlData(kWFPTextEditBoxWidgetID, ""); <br />break;      <br /><br />I am not able to Add items into list box.<br /><br />I tried based on Discussion <br />http://www.adobeforums.com/webx/.3bc43877<br /><br />but not able to locate  SDKListBoxHelper file .it is not available in SDK.<br /><br />Please ,<br />Tell me Where I am going wrong.<br /><br />Thanks,<br />Adil

    resource VSPDialogWidget (kSDKDefDialogResourceID + index_enUS)
         __FILE__,
         __LINE__,
         kVSPDialogWidgetID, // WidgetID
         kPMRsrcID_None, // RsrcID
         kBindNone, // Binding
         Frame(5,0,491,266) // Frame (l,t,r,b)
         kTrue,
         kTrue, // Visible, Enabled
         kVSPDialogTitleKey, // Dialog name
              DefaultButtonWidget
                   kOKButtonWidgetID, // WidgetID
                   kSysButtonPMRsrcId, // RsrcID
                   kBindNone, // Binding
                   Frame(9,234,89,254) // Frame (l,t,r,b)
                   kTrue,
                   kTrue, // Visible, Enabled
                   kSDKDefOKButtonApplicationKey,  // Button text
              CancelButtonWidget
                   kCancelButton_WidgetID, // WidgetID
                   kSysButtonPMRsrcId, // RsrcID
                   kBindNone, // Binding
                   Frame(394,234,474,254) // Frame (l,t,r,b)
                   kTrue,
                   kTrue, // Visible, Enabled
                   kSDKDefCancelButtonApplicationKey, // Button name
                   kTrue,  // Change to Reset on option-click.
              WLBCmpListBox   //Tree view
                   kWLBCmpListBoxWidgetID, kPMRsrcID_None,     // WidgetId, RsrcId
                   kBindAll,                                                       // Frame binding
                   Frame(299,49,475,170)           // Frame
                   kTrue, kTrue,                                             // Visible, Enabled
                   kTrue,                               // EraseBeforeDraw
                   kInterfacePaletteFill,           // InterfaceColor
                   kHideRootNode | kDrawEndLine,     // Options. Display root node
                   kFalse,          // Use H Scroll bar
                   kTrue,          // Use V scroll bar
                   20,               // fVScrollButtonIncrement
                   20,               // fVThumbScrollIncrement
                   0,               // fHScrollButtonIncrement
                   0,               // fHThumbScrollIncrement
                   2,               // Items selectable, 0 = No Selection, 1 = Single Selection, 2 = Multiple Selection
                   kFalse,          // Allow children from multiple parents to be selected
                   kTrue,          // Allow discontiguous selection
                        //The tree view is dynamically created.          
    // added to support the list elements in the list box
    resource LocaleIndex (kWLBCmpListElementRsrcID)
         kViewRsrcType,
              kWildFS, k_Wild, kWLBCmpListElementRsrcID + index_enUS
    resource WLBCmpNodeWidget (kWLBCmpListElementRsrcID + index_enUS)
         __FILE__, __LINE__,
         kWLBCmpListParentWidgetId, kPMRsrcID_None,     // WidgetId, RsrcId
         kBindLeft | kBindRight,               // Frame binding
         Frame(0, 0, 194, 20),               // Frame
         kTrue, kTrue,                         // Visible, Enabled
         "",                                        // Panel name
                   // Just a info-static text widget with about-box text view to get white bg.
              WLBCmpTextWidget
                   kWLBCmpTextWidgetID, kPMRsrcID_None,          // WidgetId, RsrcId
                   kBindLeft | kBindRight,                                        // Frame binding
                   Frame(45,1,194,18)                                             // Frame
                   kTrue, kTrue, kAlignLeft,kEllipsizeEnd                    // Visible, Enabled, Ellipsize style
                   "",                                                                 // Initial text
                   0,                                                                 // Associated widget for focus
                   kPaletteWindowSystemScriptFontId,                         // default font
                   kPaletteWindowSystemScriptHiliteFontId,                    // for highlight state.
    If you still got problems, post you email here - I'll send you the complete project/code then.
    -Marc

  • How to create a 2 column list with bullets

    How can I create a 2 columned list with bullets? When I hit tab button, the whole word and bullet moves. I am trying to create a checklist with 2 columns with a visual bullet in front of specific list items. Thanks for any help! chris

    Why not just use 2 columns?
    Or if they need to stay in step, a table?
    Peter
    btw A tab in a list changes its level, option tab moves it to the next tab on the ruler. A silly choice to make it the opposite of common sense, but they followed the lead of MsWord on this one.

  • How to make items in a list word wrap as needed and be variable heights

    I am trying to build a custom itemrenderer for the List control.  The items in the list are variable lengths of text, some of the text items will have different colors determined at runtime base on some criteria (this works fine now with my custom itemrenderer).  What I need is for the items to word wrap, and therefore for the list to display items of varying heights.  Is this possible to do?  All my attempts seem to have failed.  If I can't do this with an item renderer any suggestions about how to do this?  Thanks very much in advance to any of you gurus who are able to help me.

    Trick here is not to specify any height for the renderer so that Flex will determine the height according to the content. Also set the variableRowHeight="true"
    Here is a simple example
    <mx:ArrayCollection id="dp">
            <mx:Array>
                <mx:Object label="some very long text"/>
                <mx:Object label="some very loooooooooooooooooooooooooooooooooong text"/>
                <mx:Object label="some very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong text"/>
                <mx:Object label="some very looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong text"/>
                <mx:Object label="some very long text"/>
            </mx:Array>
        </mx:ArrayCollection>
        <mx:List dataProvider="{dp}" variableRowHeight="true">
            <mx:itemRenderer>
                <mx:Component>
                    <mx:Canvas width="100%">
                        <mx:Text width="100%" text="{data.label}"/>
                    </mx:Canvas>
                </mx:Component>
            </mx:itemRenderer>
        </mx:List>

Maybe you are looking for

  • Menu doesn't fit

    ok so I built 16:9 a project in FCP destined for dvd. I exported a self contained movie and imported that into DVD Studio Pro. in the simulator, everything looks fine, the menu letters are within the "title safe" area. so I burned it to disk but the

  • How do I burn an iMovie using a bus super drive for mac book pro

    I have a new mac book pro using the maverick operating system.  I also have a ubs super drive.  I am trying to burn an i movie to the dvd to be shown on a dvd player. It is saving as a mp4 and will not play in the dvd player.  How do I save the movie

  • Layers in DW not working! HELP!!!!

    Don't know what's going on with my DW MX 2004. I created layers with no problems until now. I'm in the right mode (Layout, Standard) when I click on the Layer icon (or use Insert, Layout Objects, Layer) nothing happens on the page, and can't draw it

  • Could some one please explain what the "Master P/W"

    I would be grateful if someone could explain why we have a Master p/w & an Admin p/w. What exactly is each needed for? I am really after clarification here to obtain a clear understanding of each one. I have a 2008 iMac, originally running Leopard no

  • PARKING FACILITY WHILE RECEIPT POSTINGS THRO F-28

    Hi, Anyone can you send me the details in FI with regard to document parking while receipt making thro the T- Code of F-28 / F-29 as we need to check these transactions before posting into FI. Thanks G. Jana