Generics in interfaces parameters

My post is a feature request. If anyone have informations on forthcoming and related developments, please send me.
I want to implement a graph class with nodes and edges collections and express in the implements section that this class supports such features (I don't take into account any delegation mechanism), graph can be considered as a String / Node map or as String / Edge one :
public class Graph implements Map<String, Node>, Map<String, Edge> {
but when compiling, I have interfaces method conflicts such as :
"The return type is incompatible with Map<String,Edge>.get(Object), Map<String,Node>.get(Object)"
because one get(Object) method is present in each interface. I would have rather liked to have a get(Node) and a get(Edge) methods. In other words, I would have liked to have Map<K,V>.get(K) method in Map interface.
Does anyone know why Java Generics are not fully introduced in interfaces and maybe in some classes ? Is it a technical reason ? A workaround ? An intermediate development stage ?
Thx.

public class Graph implements Map<String, Node>, Map<String, Edge> {The problem is that after compilation, when the object code is produced, any "type parameter" information is erased (you need to read up on Java reflection more closely).
Thus, there is only one Map class in the runtime (not one for every possible combination of type parameters). and any references to, say, Map<String,Node>.put() become, at runtime, just Map.put().
So you can't do what you want, because at compile time, your two parent interfaces are "different", but at runtime, they would be the same. The message could be better, I agree.
To do what you want:
* If your two classes (Edge and Node) have no relationship to each other, then you'll have to implement Map<String,Object>.
* If they do have a common ancestor, you can declare it as extending Map<String,CommonAncestor>.
In both cases, you'll have to, e.g. downcast the result of get() to the right type.

Similar Messages

  • Generics in Interfaces ?

    Hi all,
    Just a quick question about using generics in interfaces...is it possible to specify a type parameter for an abstract method, which is then made concrete in the implementing class ?
    One example is the Comparable interface...it would be nice if, instead of using the "Object" type, you could specify that the parameter type for the method should be that of the implementing class. This would get rid of the compareTo(Object o) methods which can present a run-time problem.
    Thanks,
    Michael Dodsworth.

    Hi again,
    As part of a wider question...is it possible to specify the type parameter of a class/interface (as you would in a new statement) as part of an "extends/implements..." statement:
    public class Foo
    extends Hashtable<Integer, String>{
    (the Hashtable example is from http://www-106.ibm.com/developerworks/java/library/j-djc02113.html)
    All type parameters on Hashtable are then tied to Integer and String in the extending class; all inherited methods have the signatures of that particular incarnation of Hashtable.
    Answering this, then answers the above question.
    Thanks,
    Michael Dodsworth.

  • How to define generics in interfaces

    I want to define an interface for Person, which has 2 attributes, 'Owner' and 'Access', but these attributes may be different types for different implementations of the interface. I have another interface that takes Person, so I have something like this:
    public interface Person<O, A>
        public abstract O getOwner();
        public A getAccess();
    public interface Entry
        public void addPerson(Person<?, ?> person);
    }I then have a base Entry implementation that does
    import java.util.ArrayList;
    import java.util.List;
    public abstract class BaseEntry implements Entry
        protected List<Person<?,?>>  persons;
        public void addPerson(Person<?, ?> person)
            if (persons == null)
                persons = new ArrayList<Person<?,?>>();
            persons.add(person);
    }and finally I have a concrete class that wants to use Entry and Person interfaces to do somthing like
    public class RealEntry extends BaseEntry
        private int personCount;
        public void addPerson(Person<String, String> person)
            super.addPerson(person);
            personCount++;
    }and I might have another implementation that does
    public class ListEntry extends BaseEntry
        public void addPerson(Person<String, List<String>> person)
            super.addPerson(person);
    }but the concrete implementations do not compile in Eclipse with the message
    Name clash: The method addPerson(Person<String,String>) of type RealEntry has the same erasure as addPerson(Person<?,?>) of type BaseEntry but does not override it
    I've read the generics tutorial, but it's not helped me. I'm not absolutely certain I should be using wildcards as opposed to generic method.
    Anyone know what I'm doing wrong?
    Thanks
    Antony

    Hi Stefan, I see how your example breaks things, thanks.
    My 'Entry' is a simple queue class. I compiles OK if I add the O, A to Entry and implementations, i.e.
    public interface Entry<O, A>
        public void addPerson(Person<O, A> person);
    }but it seems strange (to me) that I have to define the O, A types for the Entry interface - it makes it cluttered. I thought it should be possible to have a generic Entry interface that takes a Person objects without having to tell Entry the subtypes of classes that make up the O and A inside Person.
    I could be trying to do something impossible, but I something think it has to be possible as it seems such a common type of usage, i.e. I can have many classes that all define different types of Person implementations and can store them in Entry implementations.

  • Use of Interface parameters in Function module in ECC 6.0

    Hello all,
    In ECC 6.0 Version we do not use Changing/Tables interface parameters. Instead we declare a table type and use Exporting Parameters.
    Can any one send me the link to sap help where this is mentioned.
    Thanks,
    Salil

    Should be straight forward. Here's a sample...
    Exporting...
    VBSK_E     LIKE     VBSK
    ET_SPLITPROT     TYPE     VLIKP_T_SPLITPROT
    If not enough, do application help from function module....
    http://help.sap.com/saphelp_nw04/helpdata/en/d1/801e9a454211d189710000e8322d00/frameset.htm

  • How to clear JCA interface parameters in RFC call?

    hi all,
    this is my trouble:
    I have to call an RFC Function with JCA connector in an EP6 SP2. The connection it's ok and works well. But if i modify the interface parameters of the RFC function i must to reboot the portal for read the new interface.
    It's possible to read the new interface without restart the system.
    Thanks for all your helps!
    Gennaro

    hi all,
    this is my trouble:
    I have to call an RFC Function with JCA connector in an EP6 SP2. The connection it's ok and works well. But if i modify the interface parameters of the RFC function i must to reboot the portal for read the new interface.
    It's possible to read the new interface without restart the system.
    Thanks for all your helps!
    Gennaro

  • Interface parameters in Function Module -- Doubts

    Hi,
    We are developing a custom function group which will have 5-6 custom function module. When you create a function module and specify its Export/Import and table parameters, SAP mark them as "Local Interface".(You can look at the Function module source code's first line)
    But if you goto the Menu and click Edit>Interface>Globalize parameter and it will change from "Local Interface" to "Global Interface". So now you can use these interface parameters (Export/Emport or tables) without passing them explicitly in perform statement. So in other words they are easily available in the function module.
    My question are:
    1. Whats the difference between Local interface and Global interface and when should we use which. (SAP normaly use Local interface in all there function modules).
    2. If we use Global interface then is it possible that multiple instances (same fuction module called at same time with different or same data) will somehow mix the data from different calls and show unpredictable results.
    Will appreciate if someone can help me understand it from conceptual point of view.
    Thanks in advance.
    Jeet

    Hi Jeet,
    1). The difference between Local and GLobal are identified by the name itself. One makes the interface locally available and one makes it globally available. This means that, within the function group, you can access the function parameters in subroutines, as well as PBO and PAI modules.
    When to use depends, if your function module consists huge code and does massive processing in such cases its better to write subroutines and split the code into smaller sections for parallel processing. In Such cases its better to use Global interface so that you dont have to pass the interface each and every time.
    2). Yes it might affect the gloabl parameters as Unlike other global data, the contents of the global parameters of a function module are known only from the time of the call until you leave the module.
    Due to this limitations SAP has come up with OOPS concept where the data integrity is maintained.
    Cheers
    VJ

  • EREC: "Assign Values to Interface Parameters" query

    Hi All,
    I am currently on ehp4, sp4. I had a requirement to change the format of the form to display the posting. Hence i took the help of the node: technical settings>User Interfaces>Administrator and Recruiter>General Settings>Assign Values to Interface Parameters. Here i user the parameter: FORM_PUBL_INT_DOVR and parameter value as the new Z form created. The new form was visible in the publication area of the job posting.
    But when i try to view the form by searching the job posting (as a candidate), it is still displayed in the old format. i.e when i try to view the posting using the posting search functionality.
    Can anybody please tell me what is the configuration left from my side
    Note: Majority of my application is a BSP application
    Regards,
    Kishore

    Dear Kishore,
    Please do the entry in the table V77RCF_PRM_PL for custom entries. Also check the table T77RCF_UI_PARAM whether correct form is used or not ??
    Best Regards,
    Deepak.

  • Tcode for global idoc interface parameters

    hi,
      can any one say me the tcode for global idoc interface parameters.

    Hi,
    Welcome to SDN.
    check this link might help you.
    tcodes for ALE
    Regards,
    Amit
    Reward all helpful replies.

  • Tutorial for make a non-generic type class from a generic type interface

    Hi there,
    How can I make a non-generic type class from a generic type interface?
    I appreciate if somebody let me know which site can help me.
    Regards
    Maurice

    I have a generic interface with this signature
    public interface IELO<K extends IMetadataKey>
    and I have implemented a class from it
    public class CmsELOImpl<K extends IMetadataKey> implements IELO<K>, Cloneable, Serializable
    then I have to pass class of an instance CmsELOImpl to AbstractJcrDAO class constructor whit below signature
    public abstract class AbstractJcrDAO<T> implements JcrDAO<T> {
    public AbstractJcrDAO( Class<T> entityClass, Session session, Jcrom jcrom ) {
              this(entityClass, session, jcrom, new String[0]);
    So I have made another class extended from AbstractJcrDAO. Below shows the code of this class and itd constructor
    public class ELODaoImpl extends AbstractJcrDAO<CmsELOImpl<IMetadataKey>> {
         public ELODaoImpl( Session session, Jcrom jcrom ) {
         super(CmsELOImpl.class , session , jcrom, MIXIN_TYPES);
    and as you see in its constructor I am calling the AbstractJcrDAO constructor by supper method
    then I got this error on the line of super method
    The constructor AbstractJcrDAO(class<CmsELOImpl>, session, Jcrom, String[]) is undefined.
    as I know java generics are implemented using type erasure. This generics are only
    in the java source file and not in the class files. The generics are only used by the compiler and
    they are erased from the class files. This is done to make generics compatible with (old) non generics java code.
    As a result the class object of AbstractJcrDAO<CmsELOImpl<IMetadataKey>>
    is AbstractJcrDAO.class. The <CmsELOImpl<IMetadataKey>> information is
    not available in the class file. As far as I understand it, I am looking a way
    to pass <CmsELOImpl<IMetadataKey>>, if it is possible at all.
    Maurice

  • Generic classes with parameterized super class and interface

    Hello.
    I'm trying to write a generic class that looks like the following pseudo-code.
    public interface Interface {
        public Interface getSibling(...);
    public class Klass {...}
    public class MyKlass<T extends Klass, T2 extends Interface>
            extends T implements T2 {
        public T2 getSibling(...) {
            return this;
    }where Interface and Klass each have various extensions.
    I came across this problem, or challenge, while writing classes for testing my EJBs. I tried and failed various attempts.
    Is it possible to write generic classes of this nature in Java?
    If so, please tell me and others who are like me.
    Thanks in advance.

    No. That would not work.
    Beside being forbidden by the compiler, to my understanding, it cannot be done in theory either, as the parameterized types get bound at instantiation time and are not available for static reference, which both extends and implements require.

  • Generics with recursive parameters

    Hi all,
    I'm developing a class hierarchy using generics for representing graphs in our product. I end up with a lot of types such as:
    public interface Node< T extends Node<T> >
      Set< Port<N> > getPorts();
    public interface Port< T extends Node<T> >
      etc etc
    }which has caused me to run into the following bugs:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6548436
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6507317
    When I first started working with the hierarchy, I had a lot of code of the form:
    Set< Port< ? extends Node<?> > > = node.getPort();which triggered the above bugs all over the place. I've since found that I can use the shorter form:
    Set< Port<?> > = node.getPort();and it seems to just work. My question is: is this the same thing? Is the compiler smart enough to work out that the wildcard in Port<?> is really a T extends Node<T> because it's declared that way in the original class?
    Thanks for any help,
    Colin

    public class Graph implements Map<String, Node>, Map<String, Edge> {The problem is that after compilation, when the object code is produced, any "type parameter" information is erased (you need to read up on Java reflection more closely).
    Thus, there is only one Map class in the runtime (not one for every possible combination of type parameters). and any references to, say, Map<String,Node>.put() become, at runtime, just Map.put().
    So you can't do what you want, because at compile time, your two parent interfaces are "different", but at runtime, they would be the same. The message could be better, I agree.
    To do what you want:
    * If your two classes (Edge and Node) have no relationship to each other, then you'll have to implement Map<String,Object>.
    * If they do have a common ancestor, you can declare it as extending Map<String,CommonAncestor>.
    In both cases, you'll have to, e.g. downcast the result of get() to the right type.

  • EJB Web Service Interface parameters name changed

    Hi, all,
    I create a simple Session EJB 3.0 with Web Service interface in Jdeveloper 10.1.3.4. and I deployed it into the embedded OC4J server.
    The question is I found that the web service operator parameters is changed to "String_1" (actually the parameter in EJB method is String ss). And I found the WSDL file is also String_1.
    How to create the real parameter name in WSDL from EJB Web Service interface? Any help on that?
    Best Regards,
    Bill

    if you do a lookup for the name "java:comp/env/ejb/queryProc" in the servlet, the deployment descriptor of your web-archive must contain an ejb-reference with the ref-name 'ejb/queryProc'.

  • Generic ADT / Interface to implementation

    Hello, I'm new to java, hope anyone can help.
    I have to implement a priority queue that should meet the following interface (note: please ignore the '>' after 'Comparable'):
    public interface PriorityQueue<E extends Comparable<E>> {
        boolean offer(E o);
        E poll();
        E peek();
        boolean isEmpty();
    }I'm having problems with the offer(E o) method... I wrote this:
    public class ListPriorityQueue<E extends Comparable<E>> implements PriorityQueue {
    public boolean offer(E o) { return false; }
    }I thought it would work, but Eclipse gives me the following error on that line:
    "Name clash: the method offer(E) of type ListPriorityQueue<E> has the same erasure has offer(E) of type PriorityQueue but does not override it"
    It also gives me this error at class level:
    "The type ListPriorityQueue<E> must implement the inherited abstract method PriorityQueue.offer(Comparable)"
    What should I do?

    "Name clash: the method offer(E) of type
    ListPriorityQueue<E> has the same erasure has
    offer(E) of type PriorityQueue but does not override
    it"
    implements PriorityQueue<E>>
    It also gives me this error at class level:
    "The type ListPriorityQueue<E> must implement
    the inherited abstract method
    PriorityQueue.offer(Comparable)"
    What should I do?You have to either implement all the methods declared in the interface, or declare your class as abstract.

  • Does NI offer a generic LabVIEW interface for the PCI-1424 frame grabber?

    I am attempting to grab frames from a DuncanTech camera using a PCI-1424. The vendor's software was developed in the LabVIEW, but I only have the executable and they seem unwilling to provide the source file(s) - essentially, the vendor software only displays the images (no capture capabilities). In the interests of time, I would like to locate/purchase a generic LabVIEW image acquisition front-end, if available.

    MJP;
    Your PCI-1424 card should include several examples. Check the directory where the software for the camera was installed (Usually "Program Files\National Instruments\NI-IMAQ")
    Also, if you have MAX (Measurement & Automation Explorer), you can access your card from there and snap images.
    Other than that, I think you have to write your own code or ask somebody to do it for you.
    Regards;
    Enrique
    www.vartortech.com

  • Generics and interface

    Ok let's say I have an Interface A
    I have a Class B whom extends A.
    In another class, I have private member :
    List<A> xyz;
    In a method, I receive (List<B> listabc);
    I want to have in xyz a reference to all listabc items, what is the best way to do it? Cast doesn't work, so I have to iterate on abc ?
    Thanks.

    Change xyz to List<? extends A>

Maybe you are looking for

  • TS1398 I recently got a new screen for my iPhone 4s and now no wifi networks are showing up when I turn the wifi on.

    I tried resetting my networks and turning my phone on and off with the wifi turned on, but neither of it worked. I don't know what to do and I really need wifi on my phone for tomorrow.

  • Can i use Automator in app such as illustrator, Photoshop, Indesign?

    I want to use automator in illustrator. How can I use it? I tried to make services menu in illustrator cs5. but, It doesn't work. Simply explain one thing about illustrator. I want to make keyboard shortcut for file>script>script menu(this is what I

  • Best to wait befire upgrading memory or hard drive ?

    I'm a soon to be new Mac owner (looks like September), and I was wondering what you did concerning upgrades ----- Just buy the Macbook as is - run it make sure no trouble, "then" updrade the memory ? - I'm not thinking about hard drive change "maybe"

  • Reference name of page

    Hi, Does anybody know how to reference the name of a page in JavaScript? I have a form with 10 pages and want to use the same code on each page to return that page's name. Thanks for the help? Ralph

  • Regd - Delivery Block

    Dear All, What is the reason that we have the delivery block at the header level in the sales order and not for the item level Can we have a delivery block at the item level in the sales order done thru a development.. Useful Answers will be rewarded