Generic Collections and inheritance

Hi all
I have the following code:
public class GenericTest {
     public static <T,C extends Collection<T>> C process(C collection){
          // do some stuff (using T)
          return collection; // just to make a complete methode
     public void main(String[] args){
          List<String> l1 = new ArrayList<String>();
          List<String> l2;
          l2 = process(l1); // does not compile
}Compilation fails with message :
Bound mismatch: The generic method process(C) of type GenericTest is not applicable for the arguments (List<String>) since the type List<String> is not a valid substitute for the bounded parameter <C extends Collection<T>>     
My questions:
why doesn't it work?
How do I fix it?
regards
Spieler

What Compiler are you using?
Your code compiles just fine on the JDK 1.5 compiler (once I added an inport for java.util.*)
If the error message is from your IDE, you should check your IDE's web site for an existing bug, and for assistance.
This is not the correct forum since your code compiles on the SUN JDK.
Bruce

Similar Messages

  • Generic classes and inheritance

    I am in the midst of converting some database object code over to split the data from the database functionality, and I am coming into issues with generics.
    I have three bean classes:
    abstract public class Payment {
      // common fields and their get/set methods
    public final class AU_Payment
    extends Payment {
      // extra fields and their get/set methods
    public final class US_Payment
    extends Payment {
      // extra fields and their get/set methods
    }The code to write these classes to the database used to be in those classes, now I am moving them out to their own classes. I need to have a similar hierarchy so I can obtain an instance of the right class (through a factory) to write these objects to the database.
    public interface PaymentDB<T extends Payment> {
      public Result load(Connection conn, T payment, ResultInfo resultInfo) throws SQLException;
      public Result loadAll(Connection conn, List<T> allPayments, ResultInfo resultInfo) throws SQLException;
    }If I have the code for the AU_PaymentDB as the following, it won't compile:
    public class AU_PaymentDB<AU_Payment> {
      public Result load(Connection conn, AU_Payment  payment, ResultInfo resultInfo) throws SQLException {
        return null;
      public Result loadAll(Connection conn, List<AU_Payment> payment, ResultInfo resultInfo) throws SQLException {
        return null;
    }the compiler complains that the class doesn't override the interface, and I need to recode it to the following to get it to compile:
    public class AU_PaymentDB<AU_Payment> {
      public Result load(Connection conn, Payment  payment, ResultInfo resultInfo) throws SQLException {
        return null;
      public Result loadAll(Connection conn, List payment, ResultInfo resultInfo) throws SQLException {
        return null;
    load now takes just a Payment in it's signature list, and loadAll takes an untyped List.
    This means I can actually call load() with a US_Payment and it works fine, which I don't want. Also, I cannot add an AU_Payment to the list in loadAll, because the list is of the wrong type.
    How do I fix this? I want the AU_PaymentDB class to only act upon AU_Payments, and I need the loadAll to be able to add new AU_Payments to the list that is passed in.
    I hope this all makes sense,
    Chris

    ok, I'm assuming that you just forgot to paste in that AU_PaymentDB implements PaymentDB :-)
    parameterize AU_PaymentDB as follows:
    public class AU_PaymentDB implements PaymentDB<AU_Payment> {
      public Result load(Connection conn, AU_Payment payment, ResultInfo resultInfo) throws SQLException {
        return null;
      public Result loadAll(Connection conn, List<AU_Payment> payment, ResultInfo resultInfo) throws SQLException {
        return null;
    }so the interface defines a looser parameter ( Payment ) and your implementation drills it down to more specifically AU_Payment
    Bob, I believe, is your uncle

  • Generic methods and inheritance

    Hello,
    I have a class structure like this:
    A - - - - > IA (A implements IA)
    C - - - - > IC -------> IB (C implements IC extends IB)
    In IA I have a method create that returns <T extends IB<T>>:
    public interface IA {
        public <T extends IB<T>> T create();
    }IB:
    public interface IB<T> {  
    }IC extends IB like this:
    public interface IC extends IB<IC> { 
    }C implements IC:
    public class C implements IC{
    }Finally the problem: I wan to implement A in order to return an IC in the create method:
    public class A implements IA{
        public IC create() {
            IC c = new C();
            return c;
    }This compiles but I get this warning: 'A.java uses unchecked or unsafe operations.'
    What is the proper way to create such a structure?
    Thanks,
    Miguel

    you can try giving more horrible things, like giving the class you want in the method params, like :
    create(Class<IB> clazz);and then use reflection to create the instance :
    clazz.getInstance();But it's quite heavy, I think...

  • 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>();

  • EclipseLink + JPA + Generic Entity + SINGLE_TABLE Inheritance

    I was wondering if it's possible in JPA to define a generic entity like in my case PropertyBase<T> and derive concrete entity classes like ShortProperty and StringProperty and use them with the SINGLE_TABLE inheritance mode? If I try to commit newly created ElementModel instances (see ElementModelTest) over the EntityManager I always get an NumberFormatException that "value" can't be properly converted to a Short. Strangely enough if I define all classes below as inner static classes of my test case class "ElementModelTest" this seems to work. Any ideas what I need to change to make this work?
    I'm using EclipseLink eclipselink-2.6.0.v20131019-ef98e5d.
    public abstract class PersistableObject
        implements Serializable {
        private static final long serialVersionUID = 1L;
        private String id = UUID.randomUUID().toString();
        private Long version;
        public PersistableObject() {
               this(serialVersionUID);
        public PersistableObject(final Long paramVersion) {
              version = paramVersion;
        public String getId() {
    return id;
        public void setId(final String paramId) {
      id = paramId;
        public Long getVersion() {
    return version;
        public void setVersion(final Long paramVersion) {
      version = paramVersion;
        public String toString() {
      return this.getClass().getName() + "[id=" + id + "]";
    public abstract class PropertyBase<T> extends PersistableObject {
        private static final long serialVersionUID = 1L;
        private String name;
        private T value;
        public PropertyBase() {
    this(serialVersionUID);
        public PropertyBase(final Long paramVersion) {
      this(paramVersion, null);
        public PropertyBase(final Long paramVersion, final String paramName) {
      this(paramVersion, paramName, null);
        public PropertyBase(final Long paramVersion, final String paramName, final T paramValue) {
      super(paramVersion);
      name = paramName;
      value = paramValue;
        public String getName() {
    return name;
        public void setName(final String paramName) {
      name = paramName;
        public T getValue() {
    return value;
        public void setValue(final T paramValue) {
      value = paramValue;
    public class ShortProperty extends PropertyBase<Short> {
        private static final long serialVersionUID = 1L;
        public ShortProperty() {
    this(null, null);
        public ShortProperty(final String paramName) {
      this(paramName, null);
        public ShortProperty(final String paramName, final Short paramValue) {
      super(serialVersionUID, paramName, paramValue);
    public class StringProperty extends PropertyBase<String> {
        private static final long serialVersionUID = 1L;
        protected StringProperty() {
    this(null, null);
        public StringProperty(final String paramName) {
      this(paramName, null);
        public StringProperty(final String paramName, final String paramValue) {
      super(serialVersionUID, paramName, paramValue);
    public class ElementModel extends PersistableObject {
        private static final long serialVersionUID = 1L;
        private StringProperty name = new StringProperty("name");
        private ShortProperty number = new ShortProperty("number");
        public ElementModel() {
    this(serialVersionUID);
        public ElementModel(final Long paramVersion) {
      super(paramVersion);
        public String getName() {
      return name.getValue();
        public void setName(final String paramName) {
      name.setValue(paramName);
        public Short getNumber() {
      return number.getValue();
        public void setNumber(final Short paramNumber) {
      number.setValue(paramNumber);
    <?xml version="1.0" encoding="UTF-8" ?>
    <entity-mappings version="2.1"
    xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd">
    <mapped-superclass
      class="PersistableObject">
      <attributes>
      <id name="id">
      <column name="id" />
      </id>
      <version name="version" access="PROPERTY">
      <column name="version" />
      </version>
      </attributes>
    </mapped-superclass>
    <entity class="PropertyBase">
      <table name="PropertyBase" />
      <inheritance />
      <discriminator-column name="type"/>
      <attributes>
      <basic name="name">
      <column name="name" />
      </basic>
      <basic name="value">
      <column name="value" />
      </basic>
      </attributes>
    </entity>
    <entity class="StringProperty">
      <discriminator-value>StringProperty</discriminator-value>
    </entity>
    <entity class="ShortProperty">
      <discriminator-value>ShortProperty</discriminator-value>
    </entity>
    <entity class="ElementModel">
      <table name="ElementModel" />
      <inheritance />
      <discriminator-column name="type"/>
      <attributes>
      <one-to-one name="name">
      <join-column name="name" referenced-column-name="id" />
      <cascade>
      <cascade-all />
      </cascade>
      </one-to-one>
      <one-to-one name="number">
      <join-column name="number" referenced-column-name="id" />
      <cascade>
      <cascade-all />
      </cascade>
      </one-to-one>
      </attributes>
    </entity>
    </entity-mappings>
    public class ElementModelTest extends ModelTest<ElementModel> {
        public ElementModelTest() {
      super(ElementModel.class);
        @Test
        @SuppressWarnings("unchecked")
        public void testSQLPersistence() {
      final String PERSISTENCE_UNIT_NAME = getClass().getPackage().getName();
      new File("res/db/test/" + PERSISTENCE_UNIT_NAME + ".sqlite").delete();
      EntityManagerFactory factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
      EntityManager em = factory.createEntityManager();
      Query q = em.createQuery("select m from ElementModel m");
      List<ElementModel> modelList = q.getResultList();
      int originalSize = modelList.size();
      for (ElementModel model : modelList) {
          System.out.println("name: " + model.getName());
      System.out.println("size before insert: " + modelList.size());
      em.getTransaction().begin();
      for (int i = 0; i < 10; ++i) {
          ElementModel device = new ElementModel();
          device.setName("ElementModel: " + i);
        device.setNumber((short) i);
          em.persist(device);
      em.getTransaction().commit();
      modelList = q.getResultList();
      System.out.println("size after insert: " + modelList.size());
      assertTrue(modelList.size() == (originalSize + 10));
      em.close();

    This was answered in a cross post here java - EclipseLink + JPA + Generic Entity + SINGLE_TABLE Inheritance - Stack Overflow
    Short answer: No, it shouldn't work as the underlying database field type would be constant.  So either the Short or the String would have problems converting to the database type if they both mapped to the same table field. 

  • variable-class using Generic Collection

    Within my TLDs I would like to use the <variable-class> attribute as much as possible for the sake of JSP authors.
    I cannot figure out how to specify that a varAttribute will be a generic collection. IE, if I want to return a set of strings, I would like to do
    <variable-class>
    java.util.set<java.lang.String>
    </variable-class>
    Of course I must escape the <,> and I tried using < and > but it was not effective.
    Is this even possible? I would appreciate any comments suggestions.

    Currently we are using a single domain account on every machine in this kiosk area. They are using just Internet Explorer and Adobe Reader. We are using Group Policy to lock down the machines. Each station is a full computer (older Dell OptiPlex) running
    Windows 7. We are looking at the possibility of removing the OptiPlex computers and replacing them with Wyse terminals. The backend would be a cluster of 3 servers running Hyper-V 2012 R2. On those would be running Windows Server 2012 R2 RDS.  We have
    tested this setup, but when creating the VDI collection there doesn't seem to be a way to use generic domain accounts. 
    Every person that uses these does not have an AD account and it looks like that would be a problem when trying to implement this.  I was just checking here to see if anyone had any ideas or had gone through a similar setup.

  • OAM Generic Collection Services

    Hi,
    After cloning from multi node to single node, OAM Generic Collection Service is not started by default ?
    However, i manually started it.
    Is this the normal
    Thanks
    sunil

    Sunil,
    What is the error?
    Please clean FND_NODES table as follows, and run AutoConfig on the database/application tiers then:
    SQL> EXEC FND_CONC_CLONE.SETUP_CLEAN;
    SQL> COMMIT;If the above does not help, please have a look at [Note: 393706.1 - OAM Generic Collection Service shows State: The target node/queue unavailable|https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=393706.1]

  • Empty Collections and Empty Tags

    It seems that empty collections from a cast or cursor result in an empty tag. For example, the following sql:select work.work_id medlineid,
    cursor(
    select
    databankname,
    db.accessionnumberlist_ref.accessionnumberlist accessionnumberlist
    from table(dbl.databanks) db
    order by databankname) databanklist,
    cast( multiset (
    select chemical_t(
    wrkchm.cas_registry_number,
    wrkchm.term)
    from work_chemicals wrkchm
    where wrkchm.work_id=work.work_id
    order by wrkchm.term) as chemicals_t) chemicallist
    from
    works work,
    databanklist_t_v dbl
    where
    work.work_id = 96264942
    and work.work_id = dbl.work_id(+)results in the following XML:<medlinecitationset>
    <medlinecitation num="1">
    <medlineid>96264942</medlineid>
    <databanklist/>
    <chemicallist/>
    </medlinecitation>
    </medlinecitationset>Is there a way to not have these empty tags appear?
    Thanks! -- John.
    null

    David, this is about understanding the use of, and differencies between tags and collections. This is a bit hard for many new users.
    First of all searching for collections and tags can *not* be done simultaneously. You can either work with one collection only, or you can search for pictures with one or more tags.
    Next collections should be used as either temporary work sets or for special occasions like specific vacations, trips or birthdays, e.g. "Anna 5 years". You say you have a collection named "Churches". I think would have made a TAG called "Churches" instead, because a tag is for general searches that can be combined. On the other hand I might have made a collection called "Church visits July 2005" or "Summer vacation 2005" or the like.
    Another difference is that pictures in a collection can be sorted manually by drag & drop, while pictures found via tags always are shown in the order chosen in the Photo Browser Arrangement box shown bottom left in the Organizer.

  • How do I import collections and previous editing into a new copy of Lightroom 5?

    I've recently installed Lightroom 5 on a new computer.  I chose not to install my old Lightroom 3.6 on the new computer, but imported the catalog and photo folders from external drives into Lightroom.  My collections and editing did not appear to have been imported along with the catalog and photos.  What to do??

    In LR5, File->Open Catalog and then point to the location of your LR 3.6 catalog

  • How to extract data from generic view and function module

    hi experts,
    can anybody give me the steps to extract data from generic view and  functon modules.
    thanks and regards
    venkat

    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/a0f46157-e1c4-2910-27aa-e3f4a9c8df33
    https://websmp103.sap-ag.de/~sapidb/011000358700007535452002
    Hope it Helps
    Chetan
    @CP..

  • Apex Collections and dates

    Apex Collections and Dates
    I made an earlier posting today on the forum titled “‘ORA-01861: literal does not match format string’ error after my hosting company upgraded to Apex 3.2.” The issue relates to Apex collections and dates. Prior to the hosting company upgrading Apex 3.2 from 3.1 all was working OK. It seemed a reasonable assumption that the issue relates to the upgrade to 3.2. Having tested the code against another Apex 3.2 installation I am satisfied that the issue is not with Apex 3.2. That said, I am still getting the issue on the hosting site.
    To demonstrate the issue to my hosting company and this forum, I put together a simple one page application that demonstrates the issue using the least amount of code.
    I created a page with an ‘On Load – Before header” process that sets up an Apex Collection with a single value of ’20-FEB-2009’ in the c001 element as follows:
    if apex_collection.collection_exists(p_collection_name=>'THEISSUE') then
    apex_collection.delete_collection(p_collection_name=>'THEISSUE');
    end if;
    apex_collection.create_collection(p_collection_name => 'THEISSUE');
    APEX_COLLECTION.ADD_MEMBER(
    p_collection_name => 'THEISSUE',
    p_c001 => '20-FEB-2009');
    I added an SQL REPORT region to the page which uses the Apex Collection as follows:
    select to_date(c001,'DD-MON-YYYY') testdate
    from apex_collections
    where collection_name='THEISSUE'
    and to_date('20-FEB-2009','DD-MON-YYYY')
    = to_date(c001,'DD-MON-YYYY')
    When the page is run I get the ‘ORA-01861: literal does not match format string’ error.
    If I remove the following from the SQL Report Region:
    and to_date('20-FEB-2009','DD-MON-YYYY')
    = to_date(c001,'DD-MON-YYYY')
    and run the page, the date is displayed OK, i.e., c001 is converted to a date OK. This made me wonder whether it does not like the line to_date('20-FEB-2009','DD-MON-YYYY')? So I changed the where code for the report to :
    and to_date(c001,'DD-MON-YYYY')
    = to_date(c001,'DD-MON-YYYY')
    i.e., convert c001 to a date and compare it to itself. The rationale being that if the c001 converts to a date OK, then comparing c001 converted to a date with itself should not give an error. It did it gave the same error ‘ORA-01861’
    It would seem on my hosting site since the upgrade, that Apex and Oracle have problems with Apex Collection elements being converted to dates as part of the where clause.
    Now my understating of Oracle Apex collections in simple terms is that all Apex collections are held in a single Oracle table managed by a series of Apex functions. Given that all Apex collections are in the same table, could the issue be with the Oracle database when it is creating its execution plan for the query? Could Oracle be including the value of c001 from other collections (i.e., when c001 is not in a date format ) in the initial stages of its execution plan?
    I hope the above make sense and thanks in advance.
    Ian

    Scott,
    I believe I have found the answer the statistics on WWV_FLOW_COLLECTIONS$ and WWV_FLOW_COLLECTION_MEMBERS$. are out of date and Oracle is doing a full table scan instead of using the indices to select only the c001 columns that belong to the given collection_id. If I change my simple example to store the date value in c050 it works ok. (In all probability this will be the only collection on the hosted database to use c050).
    I have asked the hosting company to gather stats on all the apex tables.
    Thanks for your help
    Ian

  • I upgraded to Firefox 7.0 on Win 7 32-bit system and can no longer download personas. I setup a collection and can't use that either.

    I finally upgraded from Firefox 3.6.8 to Firefox 7.0 this morning. I don't like the default theme, so I tried to download a new persona and do not see a "wear this" button any longer. On the screen where I should see a button that installs it on my desktop, I have an option to download Firefox or to add the persona to a collection. I created a collection and added 2 themes, but even that won't allow me to actually install the persona in Firefox.

    Try a reset ...
    Press and hold the Sleep/Wake button and the Home button together for at least ten seconds, until the Apple logo appears.
    If that doesn't help, tap Settings > General > Reset > Reset All Settings
    No data is lost due to a reset.

  • It is possible to use a VOD HTTP Stream in an iTunes U Collection and/or Course?

    We wish to better comply with TEACH Act guidelines by using VOD (video on demand as opposed to real-time streaming) HTTP Streaming where an instructor is asserting educational fair use of copyrighted material.  The key component in TEACH guidelines is that the student not be able to retain the materials beyond the duration of the course.  Thus, VOD HTTP Streaming will meet this specification nicely and is supported across all of iOS and MacOS X.
    Thus, the question: It is possible to use a VOD HTTP Stream in an iTunes U Collection and/or Course?

    I knew about that, but my question is, if it is possible to use an europe power adapter.
    Because i dont want to a carry around an power adapter and a plugin adapter.
    I hope you understand what i mean.
    Sorry for my english
    Best.

  • Creation of a generic extractor and data source for the FAGLFLEXA table

    Hi All,
    Need to create a generic extractor and data source for the FAGLFLEXA table to support AR reporting. This table contains the necessary profit center information to perform LOB reporting against the AR data.
    Please advice on how to do this.
    Regards, Vishal

    Hi Vishal,
    Its seems a simple a work out.
    1.Go to RSO2 & choose the relevant option ie. whether you want to create Transactional DS, Master Data DS or Text DS.
    2. Name it accordingly & then create.
    3. Give description to it & then give table name FAGLFLEXA.
    4. Save it & activate. If you need it to be delta enabled then click over Delta & you can choose accordingly.
    If you still face some problem then do mail me at [email protected]
    Assign points if helpful
    Regards,
    Himanshu

  • Am unable to download itones app for my windows pc that site says like "Now that you've downloaded iTunes, you're just a few steps away from starting a digital entertainment collection and enjoying it on your Mac, PC, iPad, iPhone or iPod." but i couldn,t

    Dear Apple,
    I am unable to download itones app for my windows pc that site says like "Now that you’ve downloaded iTunes, you’re just a few steps away from starting a digital entertainment collection and enjoying it on your Mac, PC, iPad, iPhone or iPod." but i couldn,t find in system.
    please send the itones downloads link.
    Thanks
    suresh

    Hi Suresh,
    Thank you for your reply.
    Devices should appear in the top right of iTunes, as seen in this image:
    From:
    iTunes 11 for Windows: Connect a device
    http://support.apple.com/kb/PH12449
    If you do not see your iOS device in this menu when you connect it to your computer, it may not be recognized by iTunes. In this case, I recommend the troubleshooting steps in this article:
    iOS: Device not recognized in iTunes for Windows
    http://support.apple.com/kb/TS1538
    Best,
    Jeremy

Maybe you are looking for