Generics parameter question

I'm trying to create a binary tree that implements Map, or extends AbstractMap.package binarytree;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
public abstract class MapTest<K, D> implements Map<K, D> {
     public Set<Entry<K, D>> entrySet() {
          // TODO Auto-generated method stub
          return null;
     public void putAll(Map<? extends K, ? extends D> m) {
          Set<Entry<? extends K, ? extends D>> s = m.entrySet();
          // Error on the above line.
                //Type mismatch: cannot convert from Set<Map.Entry<capture#1-of ? extends K,capture#2-of ? extends D>> to Set<Map.Entry<? extends K,? extends D>>     
}I'm using Eclipse. It wants me to change the line to :
Set<?> s = m.entrySet();I don't understand. EntrySet() is supposed to return Set<Entry<K, D>>, where K, D are the type parameters of the Map. The type of my Map parameter, m, is Map<? extends K, ? extends D>. Shouldn't m.entrySet() return Set<Entry<? extends K, ? extends D>>?
Why is does Eclipse want me to define the return value as a Set<?>?

Let me try an answer. First of all, generics in Java are not covariant, meaning that even though Integer is a subtype of Number, List<Integer> is not a subtype of List<Number>.
While someone using putAll could pass a Map<Apple,Pears> one day, here and now the compiler assigns the artificial type names capture#1 and capture#2. While these are subtypes of K and D respectively, Entry<capture#1,capture#2> is not a subtype of Entry<K,D> according to the rule above. Consequently the assignment between the two is illegal. Wrapping Set around it makes it even worse.
One mistake made easily goes as follows: Set<A extends Wine> is a set that in the future someone will use to store all kinds of Wine derivatives. THIS IS WRONG! The set will be used to store all kinds of A derivatives.
Consequently, Entry<capture#1,capture#2> will, in the future be some very specific type. And this type is certainly not compatible with Entry<K,D>. This is why the closest possible variable definition proposed by Eclipse is Set<?>.
A lot of in depth information about this stuff is provided by [Angelika Langer|http://www.angelikalanger.com/GenericsFAQ/FAQSections/TechnicalDetails.html]. While trying to answer your question, I also put together this.
Harald.
Edited by: pifpafpuf on Dec 6, 2008 7:05 PM
Edited by: pifpafpuf on Dec 6, 2008 7:07 PM

Similar Messages

  • Determine class type of Generic Parameter (not via getGenericSuperclass()!)

    I need to know the class type of a generic Parameter. Please imagine this class:
    class MyGenericClass<T>
    }In cases where other classes derived from MyClass and defined the generic parameter (like MyDerivedClass extends MyGenericClass<String>),
    this snippets works just fine:
    (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];But now I have no inheritance but the definition of the type parameter via instantiation:
    MyGenericClass<String> entity = new MyGenericClass<String>();The method "getGenericSuperclass()" does not suit my needs because it does not target the actual class. Nor can "getTypeParameters() " help me...
    After countless trying to retrieved the type information, I still have no clue how to determine for that case that (in my example) the type parameter
    is a 'String'.
    Does anyone know the solution?

    Serethos_0 wrote:
    Sure I could pass the class type itself as parameter to be stored in 'exportClassType'. But I only tried to adapt the idea used e.g. in Generic DAOs
    as descibed here: [http://community.jboss.org/wiki/GenericDataAccessObjects]. The big difference is, that in the Generic DAO example the typed
    information is available within the class definition ..
    Besides that I am open for any other suggestion!I would recommend passing around the Class object as you say.
    Some might suggest that you make MyGenericClass abstract, forcing any instantiation to be like this:
    MyGenericClass<String> entity = new MyGenericClass<String>() {};That would indeed cause the String type parameter to be available at runtime, since you're creating an anonymous inner class. But it leads to a convoluted and extremely statically expensive instantiation pattern. Using the class object is a better solution IMO.

  • "Batch" type script - maybe generic UNIX question!

    Hey peeps,
    We just set up an email filter on Solaris 9, which has 20MB of configuration files that need backing up on a regular basis. What I would like is a short executable script which does the following:
    tar -cf the config files into a tar file, named conf-backup-DATE.tar with todays date.
    open an ftp connection, with a specified username and password
    "put" the tar file on the ftp server
    disconnect from the ftp server
    I think this is more of a generic UNIX question than a Solaris question, but I don't know any more about UNIX than I do about Solaris anyway!

    Your script defines functions which will enable you to invoke the backup. But this script only defines functions. You need to invoke them for your backup to work. The sample invocation can look like this (CODE NOT TESTED!!!):
    Setup
    Initialize
    Gethottblspace
    BeginHotbackup
    Best Regards
    Krystian Zieja / mob

  • Generic DataSource Question

    Hi Friends,
    We have generic extractor based on the function module.
    It submits the report program and returns some value.
    This function module has parameter called S_S_IF-Maxsize = I-Maxsize.
    My counter is based on this,
    Counter GE S_S_IF-Maxsize.
    Now my question is what value of S_S_IF-Maxsize is determined by system and how?
    When I am checking in RSA3 it is based on the selection screen parameters on RSA3(By default:100).
    When I test in SE37-function module it  takes 000000 by default, I may change here to test and debug. But I wanted to know that when called by BW how it takes value of S_S_IF-Maxsize.
    If somebody knows the procedure on how to debug extractor when called by BW, please let me know.
    Please suggest.
    Thanks,
    John.

    Hi,
    A simple way to check how BW calls the extractor and what values are passed is to use RSA3 itself in the source system.
    Execute an infopackage in BW and note down the request number or you can use the request number of an existing one.
    Go to RSA3 in the source system, enter your datasource details there.  There will be a button next to the execute button at the top called "Import from BW".  Click that and enter the request number and the BW system logical name and hit enter.
    The parameters from the request will be imported.  You can view them and then debug using this data.
    Cheers
    Neeraj

  • Type parameter question

    I'm trying to figure out if I can simplify this interface definition:
    public interface BaseService<T extends BaseEntity<ID>, ID> {
        public T find(ID id);
        public void persist(T entity);
    }To implement this interface, I have to do something like:
    public class CountryService implements BaseService<Country, Long> {}Where Country is defined like:
    public class Country extends BaseEntity<Long> {}My question is: Is there some way to get rid of the second type parameter in BaseService, so that I can do this instead:
    public class CountryService implements BaseService<Country> {}but still enforce the type of the id parameter on the find() method in BaseService?
    The obvious solution doesn't compile:
    {color:#ff0000}public interface BaseService<T extends BaseEntity<ID>> {
       public T find(ID id);
       public void persist(T entity);
    }{color}
    Any help is greatly appreciated!

    Hi,
    Another suggestion is to parametrize BaseEntity on a ID hierarchy
    public abstract class BaseEntity<T extends ID> {
        public abstract T getId();
    }This can lead to the following the BaseService:
    public interface BaseService<T extends BaseEntity<? extends ID>> {
        T find(ID id);
        void persist(T entity);
    }Now if you define Country as
    public class Country extends BaseEntity<ID> {
        @Override
        public ID getId() {
            return null;
    }and finally CountryService as
    public class CountryService implements BaseService<Country> {
        @Override
        public Country find(ID id) {
            return null;
        @Override
        public void persist(Country entity) {
    }Hope this help.

  • C parameter question

    Ok, so I am currently in the process in writing a C library for a small kernel I am making for fun, and my question is:
    Is it possible to have a function specify only one parameter in the code and have any extra parameters put into an array, let's call it extra[].
    Here is the code I have:
    unsigned int k_printf(char *message)
    char *vidmem = (char *) 0xb8000;
    unsigned int i = 0;
    i = (line*80*2);
    while(*message != 0) {
    if(*message=='\n') {
    line++;
    i = (line*80*2);
    *message++;
    else if(*message=='%s') {
    else {
    vidmem[i] = *message;
    *message++;
    i++;
    vidmemcount++;
    vidmem[i] = WHITE_TXT;
    i++;
    vidmemcount++;
    line++;
    return 1;
    I am currently trying to make a close but less powerful printf() equivalent. For example:
    printf("My name is %s and my friends name is %s", myname, friendsname);
    I want to be able to make an extra[] array that stores myname and friendsname in extra[0] and extra[1]. Is this possible?

    ewaller wrote:
    itsbrad212 wrote:
    Ok, so I am currently in the process in writing a C library for a small kernel I am making for fun, and my question is:
    Is it possible to have a function specify only one parameter in the code and have any extra parameters put into an array, let's call it extra[].
    Here is the code I have:
    unsigned int k_printf(char *message)
    char *vidmem = (char *) 0xb8000;
    unsigned int i = 0;
    i = (line*80*2);
    while(*message != 0) {
    if(*message=='\n') {
    line++;
    i = (line*80*2);
    *message++;
    else if(*message=='%s') {
    else {
    vidmem[i] = *message;
    *message++;
    i++;
    vidmemcount++;
    vidmem[i] = WHITE_TXT;
    i++;
    vidmemcount++;
    line++;
    return 1;
    I am currently trying to make a close but less powerful printf() equivalent. For example:
    printf("My name is %s and my friends name is %s", myname, friendsname);
    I want to be able to make an extra[] array that stores myname and friendsname in extra[0] and extra[1]. Is this possible?
    Okay, here goes:
    where is line defined, allocated, initialized?
    where is vidmemcount defined, allocated, initialized?  what is it used for?
    Avoid *80*2.  Especially in multiple places.  Use a #define in case you change the size latter. 
    Even better, how about creating records on the heap using malloc and then keeping an array of references to the records.[Edit :: Never mind -- I see what you are up to.  Ignore this]
    Rather than :
    while(*message != 0) {
    if(*message=='\n') {
    line++;
    i = (line*80*2);
    *message++;
    else if(*message=='%s') {
    else {
    vidmem[i] = *message;
    *message++;
    i++;
    vidmemcount++;
    vidmem[i] = WHITE_TXT;
    i++;
    vidmemcount++;
    How about :
    char* vm = vidmem;
    while ( *message)
    if ((*message)=='\n')
    vm=vidmem+SPAN * (++line);
    message++;
    else
    *(vm++)=*(message++);
    *(vm++)=WHITE_TXT;
    edit : fixed bug in my code
    Thanks for the tips! Any speed improvement whatsoever is crucial when doing things like this.
    Here are those defined at the beginning of the functions.h file:
    unsigned int line = 0;
    char *vidmem = (char *) 0xb8000;
    unsigned int vidmemcount = 0;

  • NTRIALS Parameter Question...

    What exactly does the NTRIALS parameter of the FCSET command do? It can't be the number of regressions the the forecast engine goes through is it?
    Also, is this the correct forum for DML questions?
    Thanks for your time.
    GGA

    Greg, it took a little digging to find this one. I'm told that NTRIALS has no effect on the forecast, however it can be queried after the forecast to see how many trials can be reported by the FCQUERY function.
    Hope this helps. This is probably as good a forum as any for DML questions.

  • A generic java question

    Hi, I am trying generic java downloaded from
    http://developer.java.sun.com/developer/earlyAccess/adding_generics/
    it works fine with "Test.java", an example included in the package, but it gives "cannot resolve symbol" error message when the source code contains something like "packagename.classname" in the type. For example:
    List<network.Node> nodeList = new ArrayList<network.Node>();
    it'll complain: cannot resolve symbol Node.
    The reason to put a package name before the class name is because there are classes in different packages with the same name.
    Any help with this problem would be appreciated.

    This is proably a dumb question, but are you using the fully qualified package name. If not, you must.
    Chuck

  • XMLP 5.6.2 Generic setup questions

    We have this configuration and wish to get started with XML Publisher:
    11.5.9 Linux Production application server
    9.2.0.6.0 Linux Production database server
    11.5.9 Linux Development/Test (shared) application server
    9.2.0.6.0 Linux Development/Test (shared) database server
    Our Fusion Middleware rep suggested that we download the XMLP562_generic.zip and install XML Publisher.
    I have read the Install Notes and have a few technical questions that the rep could not field.
    1) Where does the Publisher get installed? The application server?
    2) If so, and we install it on our shared Dev/Test server, will it affect both instances?
    3) 10g is required to 'send' or 'schedule' reports. What is the definition of 'sending'?
    4) After it is installed, will we see any changes to our 11i existing .rdf reports?
    I'd like to know these answers before we pass the instructions along to our DBAs.
    Thanks,
    -Tracy

    I know it 's been a long time since this post, but I am trying to achieve the same in 10.1.3.2 Standalone. The documentation for Standalone is not clear, or I'm missing something. Has someone gotten bursting working using data from the original xml output as the source for bursting and gotten it to work?
    If so, please help.

  • Simple parameter question ie db_name and usage in an expression

    Hi,
    I just started with SSIS with an example containing a flat xls file with 5 columns and a source table in sql.
    The example works fine no parameters etc.
    What I want to try out is to make an exception that if a certain db_name = X then the flow should be redirected to another table.
    Basicly I need help how to define a parameter to read from the source database like "select db_name as db_name" and use this in the package flow. When db_name=X then flow A ELSE flow B
    Any help is very appreciated.
    -Miracles are easy, the impossible takes a bit longer-

    Hi Paul,
    Create an object variable with name varObj and create a string variable with name as varDBName
    Use this as source query in execute sql tasK: Select <DBNamefield> from Table. In execute sql task do the following:
    On General tab: set Result set as Full Result Set
    On Result Set tab: Click Add and set Result Name as 0 and select varObj as Variable Name. This variable will capture the value returned from the select statement.
    Take a for each loop container and configure it as:
    On Collection tab: Enumerator: for each ado enumerator; ADO Object source variable: varObj; Enumeration Mode: Rows in first table.
    On Variable Mappings tab: Select varDBName as variable and set Index as 0.
    Inside the for each loop put the data flow task. Configure the data flow task and use a conditional split to redirect the rows based on varDBName as : @[User::varDBName]=="x" and so on for different outputs
    Nitesh Rai- Please mark the post as answered if it answers your question

  • Another multi value parameter question

    I have spent the last six hours researching and testing this and I am getting nowhere.  I am using CR 2008 and SQL Server 2005.  I have a main report that has a six level cascading prompt.  The values for all of the prompts are number values.  The lowest level prompt is a multi value prompt.  I need to pass the value(s) from this prompt to a subreport so I have created this formula field which I have seen in many of the posts:
    WhilePrintingRecords;
    Shared numberVar counter;
    //increments the loop so that all parameter entries can be displayed
    Shared stringVar display;
    //creates a string "running total" so that all entries can be displayed
    for counter := 1 to Count({?Hierarchy - DOUNum}) do
    display := display + ToText({?Hierarchy - DOUNum}[counter],0,";");
    display;
    I display this on my main form and I run across my first problem.  The first DOUNum is 19903 and the second is 19904.  What I see in the report though is 19,90319,904.  I need for it to be 19903,19904.  Before i knew the formula was doing this I passed this formula to my subreport for record selection there.  That subreport has the DOUNum field in it and that field is a numeric field, so when I try to put this in my record selection formula:
    {spCSSReportNCounts1;1.DOUNum} in [{?Pm-@DOUNum}]
    I get this error: A number range is required here.
    How in the world can I get around these two problems?
    TIA

    Okay, I have the formatting issue resolved.  Here is my new formula:
    WhilePrintingRecords;
    Shared numberVar counter;
    //increments the loop so that all parameter entries can be displayed
    Shared stringVar display;
    //creates a string "running total" so that all entries can be displayed
    for counter := 1 to Count({?Hierarchy - DOUNum}) do
    display := display & "," & ToText({?Hierarchy - DOUNum}[counter],0,"");
    Mid(display,2);
    This gives me 19903,19904 to pass to the subreport in my subreport link parameter - ?Pm-@DOUNum
    When I tried adding the = sign:
    {spCSSReportNCounts1;1.DOUNum} = {?Pm-@DOUNum}
    I get the error: A number is required here.
    And when I try this:
    {spCSSReportNCounts1;1.DOUNum} = [{?Pm-@DOUNum}]
    I get the error: A number range is required here.
    Which is the same error I get when i switch out the = for IN:
    {spCSSReportNCounts1;1.DOUNum} In {?Pm-@DOUNum}

  • Query parameter question

    Hi
    What are the diffrence of the query parameter in following format:
    select * from table_a where row_id=?id
    select * from table_a where row_id=:id
    select * from table_a where row_id=&idThe 1st and 2nd works if I use them as named query from Java (Toplink)
    The 2nd and the 3rd works when I use them from SQL developer. SQL developer will pop up parameter window. but the window looks diffrent with each parameter format.
    What are the diffrences?
    Thanks

    >
    select * from table_a where row_id=?idMust be a Java thing, not SQL or PL/SQL
    select * from table_a where row_id=:idThis is a bindvariable
    select * from table_a where row_id=&idThis is a substitution variable
    Edited by: Alex Nuijten on Jun 17, 2009 5:33 PM
    Edited by: Alex Nuijten on Jun 17, 2009 5:34 PM

  • SDO_GEOM.WITHIN_DISTANCE parameter question

    Hello,
    We are using a spatial function in our WHERE clause to determine whether Point A is within a certain distance of Point B. The call is:
    and SDO_GEOM.WITHIN_DISTANCE(s.location, 1000, n.location, 10) = 'TRUE'
    I can tell that the code is trying to see whether Point A is within 1000 units of Point B but what I'm trying to figure out what the unit of measurement is for the 1000 units. Could someone give me a pointer on where I can find the definition of this unit of measurement?
    Thanks for your time.
    Steve

    from the user guide:
    http://download.oracle.com/docs/html/B14255_01/sdo_objgeom.htm#sthref1756
    SDO_GEOM.WITHIN_DISTANCE(
         geom1 IN SDO_GEOMETRY,
         dist IN NUMBER,
         geom2 IN SDO_GEOMETRY,
         tol IN NUMBER
         [, units IN VARCHAR2]
         ) RETURN VARCHAR2; units
    Unit of measurement: a quoted string with unit= and an SDO_UNIT value from the MDSYS.SDO_AREA_UNITS table (for example, 'unit=KM'). See Section 2.8 for more information about unit of measurement specification.
    If this parameter is not specified, the unit of measurement associated with the data is assumed. For geodetic data, the default unit of measurement is meters.
    Note:
    1. that this is a function that does not use spatial index.
    did you in the where clause explictly defined pointa and pointb?
    if not, you should use the operator SDO_WITHIN_DISTANCE http://download.oracle.com/docs/html/B14255_01/sdo_operat.htm#sthref1150.
    Luc
    Edited by: lucvanlinden on Oct 1, 2008 8:26 PM

  • Subreport parameter question

    I have a report on liquor licensees that brings in zero to several values (extra license privileges)  in a subreport.  It works ok but I can't get a parameter/selection criteria to work.  I can get it to select based on the parameters, but when I don't put in any parameters I don't get any records, and when I put in all the choices, I get them, but I don't get the records with no extra license privileges, i.e., no records in the subreport's table.
    The report already has several parameters that don't draw from the subreport.
    I tried using a left outer join.
    I don't know if I have the subreport links right.  Right now I'm back to the beginning, without that parameter.  Will someone please help me?
    Edited by: Lauri Malone on Aug 21, 2008 10:46 PM

    Then I see two options:
    1. Conditionally suppress details section and here are the steps
    - have subreport in Details A section and pass subreports results as shared variable to main report
    - Conditionally suppress all other Details (B,C,D,.etc) sections based on shared variable
    2. Switch main report and subreport
    -Your current subreport could be a main report where based on parameters you can concatenate a list of records that you want to select.
    - Your current main report could be added as a subreport in Report Footer and list of records passed as a parameter in subreport links
    I am ready to explain details depending on which option you prefer

  • Generic Extraction Question

    Hello,
    I created generic Data Source as ZMM_MAIN, I selected LBKUM(Total Valuated Stock) data type as "QUN" refference field as 0UNIT in the data source so that I can have selection criteria in infopackage.
    When i replicate this datasource in BI , Under InfoPackage "Data Selection" tab I'm not seeing LBKUM
    I'm not sure why its not showing? because of its Quantity Field?
    Your help would be appreciated
    Thanks

    On SAP ECC 6.0  under data source I choose option Select check box for this field
    When I run RSA3 I can see the slection field but when I replicate in BI , I'm not seeing that field under "Data Selection" tab why?
    Please provide the solution
    Thanks

Maybe you are looking for

  • Error in running client program

    hi , i am tring to run a sample client program for web service i am getting the following error: Exception in thread "main" java.lang.NoClassDefFoundError: BatchWebServices/axis /browsing/Sample1 (wrong name: browsing/Sample1) at java.lang.ClassLoade

  • Iphone/Ipod not recognised in Itunes

    Hopefully someone can help here.  I;ve never had a problem with this.  All of a sudden my itunes doesn't recognise the ipod touch or my iphone 4.  I'm using a dell laptop with windows vista. I've tried all the steps on here and uninstalling itunes an

  • Cant sync iPhone because itunes says this computer is no longer authorised

    whenever i try to sync my iPhone 5s to my computer (iMac.. the older/thick one), it backs up and works fine until it starts to download music and apps. it says that it cant sync to my iPhone because the computer is no longer authorised for the purcha

  • I have OSX 7.2 Lion but cannot figure out how to setup a signature on apple mail for my emails.

    I just converted to OSx 7.2 Lion and starting using the applle mail instead of Entourage because I got a I phone 4S so I wanted to use the cloud.  But I can not figure out how or if you can setup a signature to use when emailing.  I had it with Entou

  • How to re-set Apple Router after we lost electricity?

    We lost electricity last evening.  Apple Router is amber color.  For some reason our network switched to an Apple Network which is unlocked so I get internet but no phone service.  Has anybody had to deal with this issue and if so how did you resolve