EnumMap with interfaces

I have bunches of Enums that I want to have a common behavior, so I created an interface, and implement that in each enum:
interface Z {
    int doStuff();
enum X implements Z {
    A, B, C;
    int doStuff(){ ... }
}Now I want to use an EnumMap with keys consisting of enums implementing Z:
MyClass c = ...
EnumMap <Z, MyClass> map = new EnumMap <Z, MyClass>( Z.class );
for ( Z z : X.values()){
    map.put( x, c );
}The compiler does not like the declaration (among other things). If I replace the declaration with:
EnumMap <? extends Z, MyClass> map = new EnumMap <Z, MyClass>( Z.class );then it likes the declaration to the left of the "=", but not the rest.
What am I doing wrong? Note that if I replace the EnumMap declaration with:
HashMap <Z, MyClass> map = new HashMap <Z, MyClass>();Then everything works, but would like to use EnumMap. If I declare:
EnumMap map = new EnumMap( Z.class );then I have to do some casting, and also get unchecked warnings.

Thanks for the response! In my example, I'm only putting enums from one enum class in there; in fact, I thought the whole purpose of having to pass a class object for the Enum to the constructor, was to identify the class.
Oh, well, if it wasn't meant to work, I'll go back to the HashMap.
Another question: Along the same vein, I have the following "awful" utility routine:
    public static Enum getEnum( Object[] enums, String string ){
         return Enum.valueOf( ((Enum) enums[ 0 ]).getClass(), string );
    }I have many groups of enums that are identified by name in external data. When I read the external data, I need to identify them with the actual enum element. The valueOf() method is of course perfect for this. Unfortunately, all I have in the routine that reads the data, is the array of values; eg, X.values() (from my enum X in my original message) is passed in.
The above code works perfectly (and even throws the appropriate exception when there is no match), but gives another unchecked conversion message. Any ideas as to how to get rid of the message? Subclassing each enum to have a lookup() method that just maps to valueOf() would probably work, but it's clumsy and not really practical with about a hundred enum declarations.
I thought the whole point of casting in Java was to in effect say, "Check this at run-time; I know what I'm doing."

Similar Messages

  • TS1702 I had this Scrabble on my iPad2 and began to have connection problems, it would lock in the "connecting" position. This is not the first time Scrabble has had problems with interface. Typically customers delete the Ap then download it again to rein

    I have contacted EA about this and can find no help. I had this Scrabble on my iPad2 and began to have connection problems, it would lock in the "connecting" position. This is not the first time Scrabble has had problems with interface. Typically customers delete the Ap then download it again to reinstall it. During the process you sign in and approve the purchase KNOWING that another window will open saying that you have previously purchased it and that there is no charge. So what happened this time? It will not connect and all of my saved and current games are wiped out. I want my money back, this game interface is pretty junk and operates like some ancient DOS program,,bug,bug,buggy. I want my money back.

    Go here:
    http://www.apple.com/support/itunes/contact/
    and follow the instructions to report the issue to the iTunes Store.
    Regards.

  • Incompatible with interface - Exception in Adapter Module

    Hi Experts,
    I have a custom adapter module deployed on PI 7.1. Once i post any message, i am getting below exception in CC monitoring.
    Message processing failed. Cause: java.lang.ClassCastException: class $Proxy3125_10002:sap.com/ClearModule_EAR @ com.sap.engine.boot.loader.ResourceMultiParentClassLoader @ 6daa7537 @ alive incompatible with interface com.sap.aii.af.lib.mp.module.ModuleLocal:library:com.sap.aii.af.lib @ com.sap.engine.boot.loader.ResourceMultiParentClassLoader @ 15d75e80 @ alive
    I used NWDS 7.1 to develop the module.
    the EJB is stateless.
    Can any one have any idea about the exception.
    Please help me out here.
    Thx in advance,
    Brian

    Hello,
    i forgot to modify the four interfaces' name when i create the EJB, ie my Bean class is "ss.cod.de.EjdBean", then the "Remote Interface" & "Home Interface" are setted respectively and defaultly as "ss.cod.de.EjdRemote" & u201Css.cod.de.EjdHomeu201D, the u201CLocal Interfaceu201D & "LocalHome Interface" are the same to the two interface above.
    everything was well while i rectified all the interfaces as "com.sap.aii.af.lib.mp.module.ModuleHome", "com.sap.aii.af.lib.mp.module.ModuleLocal", "com.sap.aii.af.lib.mp.module.ModuleLocalHome" and "com.sap.aii.af.lib.mp.module.ModuleRemote".
    hope its help 4 u.
    good luck.
    thx & br,
    Brian

  • Need help with interface development

    Hi i need help with requirement below with developing interface between or online order system and sap plz lemme know what is bapi i use for creating customer, update and assigining partner id to costumer.
    SAP Development
    1.     Using standards SAP functional module (with BAPI), create interface that will create/change Ordering party customer in SAP. Following fields are mandatory for customer creation:
    •     MANDT     Client
    •     VKORG     Sales organization
    •     VTWEG     Distribution Channel
    •     SPART     Division
    •     KDGRP     Customer Group (= “ZORP)
    •     KUNNR     Customer number
    •     NAME1     Name 1
    •     NAME 2     Name 2 (if required)
    •     SORTL     Search term (short description)
    •     ZZALTKN     Search term 2 (old customer number)
    •     LAND1     Country
    •     ORT01     City
    •     PSTLZ      Zip Code
    •     REGIO      Region (state in USA)
    •     STRAS     Street
    •     TELF1     Primary telephone number
    •     TELFX     Primary Fax number
    •     ZZPRPLANS     Payment Plan
    •     CCINS     Payment card: Card type
    •     CCNUM     Payment cards: Card number
    •     CCDEF     Payment Card: Default Card Indicator
    •     ZBDGID     Customer Budget ID
    •     ZHOLD     Budget Hold indicator
    •     ZZCOSTCENT     Cost Center
    2.     Upon successful customer creation system will issues “S” (success) message that customer has been created.
    3.     New ordering party customer created in step ½, will have to be assigned as new partner to its belonging Sold-to/Ship-to customer. Use standard SAP customer functional module in order to perform this partner ID assignment. Partner ID for ordering party should be “ZO”.
    1.7     Enhancement Functionality
    Apart from creating a new interface to do the required functionality, the Order Create Interface also has to be changed to accommodate a field to pass the Ordering Party Number on the Order. The technicalities of how we are going to implement the interface will be laid out in the Tech Specs.
    Thanks
    in advance

    You have double posted, please mark this one as "solved on my own" and refer to this thread
    need help with interface development
    Regards,
    Rich Heilman

  • Problem with interfaces

    Greetings everyone!!! Todays' question has to do with interfaces. Anyone who might be able to help is welcomed!!!
    This is my main, which constracts new object of the type Rectangle and employee and tries to find the average and the maximum area and salary accordingly
    import java.awt.Rectangle;
    public class DataSetTester
         public static void main(String[] args)
              Measurer m = new RectangleMeasurer();
              DataSet data = new DataSet(m);
              data.add(new Rectangle(5,10,20,30));
              data.add(new Rectangle(10,20,30,40));
              data.add(new Rectangle(20,30,5,10));
              System.out.println("Average area = " + data.getAverage());
              Rectangle max = (Rectangle) data.getMaximum();
              System.out.println("Max area Rectangle = " + max);
                                    Measurer x = new EmployeeMeasurer();
              DataSet data1 = new DataSet(x);
              data1.add(new employee("Mike", 1500,10));
              data1.add(new employee("fgh",2000,10));
              employee max1 = (employee) data.getMaximum();
              System.out.println("Max employee = " + max);
    }This is the DataSet class which provides the methods to find the average and the maximum
    public class DataSet
         public DataSet(Measurer aMeasurer)
              sum = 0;
              count = 0;
              maximum = null;
              measurer = aMeasurer;
         public void add(Object x)
              sum = sum + measurer.measure(x);
              if(count == 0 || measurer.measure(maximum) < measurer.measure(x))
                   maximum = x;
              count++;
         public double getAverage()
              if(count == 0)
                   return 0;
              else
                   return sum / count;
         public Object getMaximum()
              return maximum;
         private double sum;
         private Object maximum;
         private int count;
         private Measurer measurer;
    }This is my interface
    public interface Measurer
         double measure(Object anObject);
    }The classes that implement the interface
    import java.awt.Rectangle;
    public class RectangleMeasurer implements Measurer
         public double measure(Object anObject)
              Rectangle aRectangle = (Rectangle) anObject;
              double area = aRectangle.getWidth() * aRectangle.getHeight();
              return area;
    public class EmployeeMeasurer implements Measurer
         public double measure(Object anObject)
              employee anemployee = (employee) anObject;
              double payment = anemployee.getsalary() * anemployee.getmonths();
              return payment;
    }And the class employee
    public class employee
         private String name;
         private double salary;
         private double months;
         public employee()
              name = "";
              salary = 0;
              months = 0;
         public employee(String newName, double newSalary, double newMonths)
              name = newName;
              salary = newSalary;
              months = newMonths;
         public String getname()
              return name;
         public double getsalary()
              return salary;
         public double getmonths()
              return months;
    }Everything compiles but when I execute I get the desired results for the rectangle class(average and maximum)
    , but it does not work for employee.
    I get: Exception in thread main java.lang.ClassCastException: java.awt.Rectangle
    at DataSetTester.main(DataSetTester.java:18)
    Edited by: mixalissen on 26 ??? 2008 10:29 ??

    max,
    What you are constructing is called a "dirty" collection... as the negative connotation suggests, that isn't the recommended practice.
    The recommended practice is to treat "disparate things" as distinct types... and if you require collections of those things then you create two individual and distinct collections.
    However, in your example, Employee and Rectangle have "behavior in common" so you can (even if it doesn't make a lot of sense in "the real world") create an interface, which (among other things) allows you to create a collection of the-type-of-that-interface.
    So your DataSet should contain Measurable 's (note: not Measurer's)... and Rectangle and Employee should both implement Measurable (hint: think Rectangle is Measurable; not Rectangle is a Measurer; and never RectangleMeasurer (yuck))... and then of course you'll need to move the appropriate measure method to Rectangle and Employee.
    Cheers. Keith.

  • Can we create objects with interface

    can we create objects with interface,if yes then where we implement the
    methods,can we type cast any object with inerface kind of object,if yes what kind
    of objects we can type cast

    can we create objects with interface,if yes then where we implement the
    methods
    Objects are created with classes, not interfaces, which are abstract.
    can we type cast any object with inerface kind of object,if yes what kind
    of objects we can type cast
    Objects may be cast to interfaces, but only if an object's class or one of its superclasses actually implements the interface.

  • Free book with interface designing?

    hi all,
    i was just wondering if anyone of you know about free book with interface and layouts that i can download.
    kindly let me know the website from where i can download it.
    regards

    Google is your friend!

  • Report with interface

    There is a report needed which will be started with a variant by a job.
    Reportname: ZRF_INT_SPOOL_SEND
    That report is supposed to copy each day the lists of several interfaces from
    the spool into a file and to send this file as an attachment by email.
    Parameters of this report are:
    -     interface numbers(several!)
    -     mail addresses of the receivers
    This report finds the spoolnumbers of the lists, which were created by the interfaces run.
    The spool numbers are found in the table TSP01.
    With the help of these spool numbers the lists can be read in the spool and copied into a file.
    The report sends this file as an attachment by email to the receivers.
    If the report finds no list for an interface on this day, an error message has to be sent by that email.
    In the field ’subject’ of the emails the text ‚SIXSIGMA’ is required.
    The spool numbers are found in the table TSP01. The fields RQTITLE and RQTIME are key.
    The functional module RSPO_RETURN_ABAP_SPOOLJOB
    can be used. It reads with import parameter spool number a list from the spool into an internal table.
    For sending an email e.g. the functional module SO_NEW_DOCUMENT_ATT_SEND_API1 can be used.
    how to start the coding with this
    can you send me the code to proceed further

    have a look at http://www.thespot4sap.com/Articles/SAP_Mail_SO_Object_Send.asp

  • External component usage with interface node

    Hi everyone,
    I have component A , which has an interface node with Input element checked:
    Nodes     
    Node Name     IF_HROBJID
    Interface Node     1
    Input Element (Ext.)     1
    Dictionary structure     ZHR_HROBJID_LIST
    Cardinality     0..n
    I have another component: Component B Where I want to bind a table to this interface node.
    In component B :
    1. I definied the Componenet Usage of component B in the componenet controller.
    2. I drag & drop the IF_HROBJID node  to the component controller's context (the node is mapped)
    But when I try to bind a table, I always get the " The Mapping to Node COMPONENTCONTROLLER.1.IF_HROBJID Has Not Been Completed. "  error.
    nd_if_hrobjid = wd_context->path_get_node( path = 'IF_HROBJID' ).
    nd_if_hrobjid->bind_table( lt_if_hrobjid ).
    Can someone tell me what is the problem, and how can I solve it?
    Thanks
    N.

    Hi,
    Here you are trying to use component A in component B right?
    Then what you need to do is:
    1. Declare the component usage of A say A_USAGE in properties tab of component B.
    2. Create a node say 'DATA' in component controller of component B. The node 'DATA' would have the same structure as the node in your component A.
    3. Fill the node 'DATA' in component controller's method.
    4. Under your webdynpro component B, you will see Component Usages -> A_USAGE. open interface controller inside that.
        Goto context tab and drag the 'DATA' node from component controller of B on to the node in interface controller.
    Hope this is clear!
    Best Regards,
    Srilatha

  • Use a VI (with interface) in another program by DLL

    Good afternoon,
    I have a problem I cannot solve at all. I have an understoodable VI. It runs properly. I can make a dll of this VI. And I want to call this dll in another program. The problem is, I have to wrap the dll with VS 2003 C++ to run in Digital Micrograph. When I call the dll, I can not control it since I cannot access to the graphical interface of Labview. Is there a way to export the graphical front panel in another software on the basis of a dll ?
    Thanks for any help.
    Solved!
    Go to Solution.

    I am not sure if you are able to view the front panel elements to manually change them, but you can set up the front panel elements using the Connector Pane and then reference them in the function prototype during the DLL build:
    Connect the front panel elements to the Connector Pane
    2. Build a DLL using the Build Specifications item in the Project
    3. Export your VI in the Source Files section in the pop-up that lets you configure your VI. 
    4. Once you click the blue arrow in step 3, you will be presented with a new popup to configure the function prototype (how you will call the function in Visual Studio).
    This is where you can map the front panel elements to the C function.  The "x", "y", and "return" refer to the controls/indicators in the first image.  (For instance, the sample VI I used just summed 2 numbers using "add" function.)
    NOTE:  You must have the LabVIEW Run Time Library installed on any computer where you wish to reference this DLL. 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If someone helped you out, please select their post as the solution and/or give them Kudos!

  • BPM: Transformation Error with Interfaces/ MT's in different namespaces

    Hi all,
    Developing an integration process on XI 3.0 SP20 I'm facing following problem:
    I've created a transformation mapping interfaces/ message types from different software components/ namespaces.
    Softwarecomp. 1 is used for the mappings and integration processes
    Softwarecomp. 2 and 3 are used for the interfaces/ message types for incoming and outgoing messages.
    Softwarecomp. 2 and 3 are assigned to Softwarecomp. 1.
    The error message is that the container types do not fit the types of source- and target messages.
    When I copy all objects in Softwarecomp. 1 everything works fine but I don't want to mix it all up.
    I've tried playing with XML-Namespaces in the message types (same XML-NS, like "test" for both MT's, also removing the XML-NS's) but it still doesn't work.
    How can I realise a transformation with objects from different SC's and NS's?
    Thanks in advance!
    Karsten

    I've created another integration process with simple example messages and it really seems to be impossible to do a transformation with message types from different software components.
    I've seen a transformation where they have done it though.
    What did I overlook??

  • Problem with interface - when send the data for PA0002

    Hi Gurus,
        I am interfacing employees data from one system to another system  with all the PA infotypes.
    we are using the fuction module " HR_MAINTAIN_MASTERDATA " to upload the master data. Here the problem is, when we send the data - in destination system all the segments have the data correctly . But middle name is not loaded in to the system. Problem with only middle name.
    But, here strange thing is, when i resend the idocs it is laoded correctly all the fields with middle name also.
    I am unable to figure out the problem .. Please let me know if you have any advise on this ..
    Thanking you.
    Regards,
    Giridhar Pujari

    Hi Sikindar,
       Technical name is corrent .. and once you resend the idoc, you can't see the problem again.
    Regards,
    Giridhar Pujari.

  • Subclass with interface can't be used in place of superclass?

    So I've searched through the forums and haven't found much of a real answer to this yet--at least, the keywords I tried resulted in nothing. This should also be a quickie--it seems pretty simple, but I'm stumped after spending so long working.
    So the problem is as follows. I need to ensure that certain Swing components in my application always implement a certain set of methods, so naturally this lends itself to an interface. I don't think an abstract class would be necessary in this case since these objects are going to be pretty radically different from each other in terms of function.
    I create my interface, we'll call it "Presentation". I create an object "PaintingPanel" which implements the interface, and since I'll need to add it to my Swing application, I have it extend JLabel, or some other JComponent.
    I thought this would work, however, JBuilder complains about the following lines of code. The instantiation is fine, but adding it gives me trouble.
    Presentation myPres = new PaintingPanel();
    myJPanel.add(myPres);What am I doing wrong exactly? Should I scrap the interface then and go with an abstract class? I can't just cast this, can I?
    Thanks in advance.

    I don't have a "this is the right way to do it" answer for you, but look at it this way.
    First, you're saying "Presentation myPres..." so all you're promising about myPres is that it "is-a" Presentation, and that it "is-a" everything the Presentation extends/implements.
    Then you want to call JPanel.add(myPres), but JPanel.add requires a Component (I think). As far as the compiler knows, myPres is a Presentation, which, since it doesn't extend Component, "isn't-a" Component.
    There are a couple things you could do.
    * Declare it as MyClassThatImpelmentsPresentationAndExtendsComponent or whatever it is. If you're expecting to treat this thing as both a Presentation and a Component, this seems to make the most sense.
    * Cast it, as stevejluke suggested.
    * Call add(myPres.getComponent()), where the getComponent is a method you add in case you[i] don't want all your Presentation implementations to have to extend Component, but[i] do  want to be able to use the Presentation (or something associated with it) in a Component context. For those Presentation implementations that do extend Component, you can just have the method return this.
    There are probably other options, depending on your actual requirements. No matter what though, the key is to be driven by the fact that add requires a Component, so you need some way to guarantee the compiler that that's what you're passing.

  • Problem in QPM 4 with interface group async

    hi.i have a question.i have deployed my wan routers QoS without any software and now i have to deploy same one with QPM 4 and there is a problem.i want to assign a service policy to interface group async with qpm but it doesnt detect int group async and it detects all my async interfaces separately interface async 1/0 - 1/29. my QPM is patched with latest patches but when i fetch my running config from a router it detects that policy not under the interface group async but under each interface async X separately. how can i deploy a policy map under the interface group async not under separated async interfaces?? please help

    The service policy that you have applied to the multilink gets into
    affect only when the multilink is congested.
    Follow the URL for the configuration of the QOS :
    http://www.cisco.com/en/US/docs/ios/12_4/qos/configuration/guide/qslfisrl.html

  • Oo abap with interface.

    Hi friends,
    I am very much new to the abap objects,
      i am finding vry much difficult in solving the
    Interface program with class.
    I Need the tutoriols about how to write a program using interface
    and to get a good knowledge about this.
    thanks and regards,
    Vijay
    Moderator Message: Tutorials can be found by Searching!
    Edited by: kishan P on Nov 16, 2010 11:03 AM

    You have already been warned [once|/message/9725734#9725734 [original link is broken]], this is your second warning. A third will result in your user being submitted for deletion.
    Thread locked

Maybe you are looking for

  • Create a signature capture for Windows Phone 8.1 App

    I am creating a Windows Phone 8.1 app with signature capture control on one of my page. I am looking for an approach using C# so that I can draw points on a XAML with Canvas control. But it seems like that InkPresenter name space is removed from Wind

  • Delete statement: how to get count of affected rows in a variable

    Hi folks I write a proc which deletes data from bunch of table based on data value. i want to produce a report which will have 1 line for each table like: Del: Table name : number of rows I parse delete statement into variable and use execute immedia

  • How to purchase a license for Macromedia Flash Professional 8?

    have a project using the old version? the adobe online chat support suggested to ask the question here.

  • Sender file channel issue

    Hello All, Here I have a problem with sender file communication channel. THe channel is not able to pick a file as the file format is not correct andf throwing exception in the channel which is expected. But Its not allowing to go and pick the other

  • Exchange Server 2007 shows email as "Receive" but not "Deliver"

    Hi Guys We have Exchange Server 2007 inside of a SBS 2008 set up. One specific email from a regular sender wasn't received by the recipient. The recipient is used to receiving messages from this sender and the email is not hiding within Outlook. Exch