Interfaces having methods of same signature but different return types

I have two interfaces in two files:
public interface InterfaceA
int f();
public interface InterfaceB
void f();
Now I want to write a class that implements these two interfaces. Is it possible? If yes, could you please provide a code example?

The easiest thing would be to change one of the names! Another approach is to have views of the class implement one or both interfaces.
Both:
class C {
    private InterfaceA a = new InterfaceA() {
        public int f() {
            return 0;
    public InterfaceA asA() {
        return a;
    private InterfaceB b = new InterfaceB() {
        public void f() {
    public InterfaceB asB() {
        return b;
}One:
class B implements InterfaceB {
    private InterfaceA a = new InterfaceA() {
        public int f() {
            return 0;
    public InterfaceA asA() {
        return a;
    public void f() {
}

Similar Messages

  • Two methods with same name but different return type?

    Can I have two methods with same name but different return type in Java? I used to do this in C++ (method overloading or function overloading)
    Here is my code:
    import java.io.*;
    public class Test{
    public static void main(String ar[]){
    try{          
    //I give an invalid file name to throw IO error.
    File file = new File("c:/invalid file name becasue of spaces");
    FileWriter writer = new FileWriter(file ,true);
    writer.write("Test");
    writer.close();     
    } catch (IOException IOe){
         System.out.println("Failure");
    //call first method - displays stack trace on screen
         showerr(NPe);
    //call second method - returns stack trace as string
            String msg = showerr(NPe);
            System.out.println(msg);
    } // end of main
    public static void showerr(Exception e){
         StringWriter sw = new StringWriter();
         PrintWriter pw = new PrintWriter(sw);
         e.printStackTrace(pw);
         try{
         pw.close();
         sw.close();
         catch (IOException IOe){
         IOe.printStackTrace();     
         String stackTrace = sw.toString();
         System.out.println("Null Ptr\n" +  stackTrace );
    }//end of first showerr
    public static String showerr(Exception e){
         StringWriter sw = new StringWriter();
         PrintWriter pw = new PrintWriter(sw);
         e.printStackTrace(pw);
         try{
         pw.close();
         sw.close();
         catch (IOException IOe){
         IOe.printStackTrace();     
         return sw.toString();
    }//end of second showerr
    } // end of class
    [\code]

    Overloading is when you have multiple methods that have the same name and the same return type but take different parameters. See example
    public class Overloader {
         public String buildError(Exception e){
              java.util.Date now = new java.util.Date() ;
              java.text.DateFormat format = java.text.DateFormat.getInstance() ;
              StringBuffer buffer = new StringBuffer() ;
              buffer.append(format.format(now))
                   .append( " : " )
                   .append( e.getClass().getName() )
                   .append( " : " )
                   .append( e.getMessage() ) ;
              return buffer.toString() ;
         public String buildError(String msg){
              java.util.Date now = new java.util.Date() ;
              java.text.DateFormat format = java.text.DateFormat.getInstance() ;
              StringBuffer buffer = new StringBuffer() ;
              buffer.append(format.format(now))
                   .append( " : " )
                   .append( msg ) ;
              return buffer.toString() ;
         public String buildErrors(int errCount){
              java.util.Date now = new java.util.Date() ;
              java.text.DateFormat format = java.text.DateFormat.getInstance() ;
              StringBuffer buffer = new StringBuffer() ;
              buffer.append(format.format(now))
                   .append( " : " )
                   .append( "There have been " )
                   .append( errCount )
                   .append( " errors encountered.")  ;
              return buffer.toString() ;
    }Make sense ???
    Regards,

  • Same functions with different return types in C++

    Normally the following two functions would be considered the same:
    int getdata ( char *s, int i )
    long getdata ( char *s, int i )
    Every other compiler we use would resolve both of these to the same function. In fact, it is not valid C++ code otherwise.
    We include some 3rd party source in our build which sometimes messes with our typedefs causing this to happen. We have accounted for all of the function input types but never had a problem with the return types. I just installed Sun ONE Studio 8, Compiler Collection and it is generating two symbols in our libraries every time this occurs.
    Is there a compiler flag I can use to stop it from doing this? I've got over 100 unresolved symbols and I'd rather not go and fix all of them if there is an easier way.

    Normally the following two functions would be
    considered the same:
    int getdata ( char *s, int i )
    long getdata ( char *s, int i )Not at all. Types int and long are different types, even if they are implemented the same way.
    Reference: C++ Standard, section 3.9.1 paragraph 10.
    For example, you can define two functions
    void foo(int);
    void foo(long);
    and they are distinct functions. The function that gets called depends on function overload resolution at the point of the call.
    Overloaded functions must differ in the number or the type of at least one parameter. They cannot differ only in the return type. A program that declares or defines two functions that differ only in their return types is invalid and has undefined behavior. Reference: C++ Standard section 13.1, paragraph 2.
    The usual way to implement overloaded functions is to encode the scope and the parameter types, and maybe the return type, and attach the encoding to the function name. This technique is known as "name mangling". The compiler generates the same mangled name for the declaration and definition of a given function, and different mangled names for different functions. The linker matches up the mangled names, and can tell you when no definition matches a reference.
    Some compilers choose not to include the return type in the mangled name of a function. In that case, the declaration
    int foo(char*);
    will match the definition
    long foo(char*) { ... }
    But it will also match the definitions
    myClass foo(char*) { ... }
    double foo(char*) { ... }
    You are unlikely to get good results from such a mismatch. For that reason, and because a pointer-to-function must encode the function return type, Sun C++ always encodes the function return type in the mangled name. (That is, we simplify things by not using different encodings for the same function type.)
    If you built your code for a 64-bit platform, it would presumably link using your other compilers, but would fail in mysterious ways at run time. With the Sun compiler, you can't get into that mess.
    To make your program valid, you will have to ensure your function declarations match their definitions.

  • Any solution to unable to retrieve purchased apps in a new iPad - using same Apple ID, same country but different payment method.

    Any solution to unable to retrieve purchased apps in a new iPad using same Apple ID, same country but different payment mode?

    Hello there, Tag2011.
    The following Knowledge Base article offers up great information on the process of downloading a previous purchase:
    Download past purchases
    http://support.apple.com/kb/ht2519
    Particularly useful in your instance:
    Before you begin
    Sign in with the Apple ID that you used for the original purchase.
    See which Apple ID you used to download an item.
    See if the content is available for redownload. Previously purchased items might not be available if they're no longer on the iTunes Store. If you changed your Apple ID from one country to another, you can’t download items you purchased in a previous country.
    and then to download again:
    Apps
    Tap App Store.
    If you're using an iPhone or iPod touch, tap Updates, then tap Purchased.
    If you're using an iPad, tap Purchased.
    Find the item that you want to download.
    Tap the Download icon. After the app downloads, you can open it from the Home screen.
    If you can't find the item that you purchased in the iTunes Store, report a problem with the item. You can report a problem with a purchase made within the last 90 days.
    If you have a problem with an older purchase, contact iTunes Store support.
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro.

  • I would like to transfer music from my account to my wife`s on the same Mac but different users, i want her to have her own i tunes account but now that she has downloaded all of her stuff in my account , she has to "erase and sync"  how can i troublshoot

    I would like to transfer music from my account to my wife`s on the same Mac but different 2 users (hers and mine), i want her to have her own i tunes account but now that she has downloaded all of her stuff in my account , she has to "erase and sync" all of her stuff when she opens her account which has nothing in it!, how can i send stuff from my i tunes account to hers? same computer different users, how can i trouble shoot please help!!??

    how do i share then? can she upload music if we share it somehow?
    If so how??
    i am also having the same problems now with IPhoto, she has all of her/our pics in my IPhoto library.
    I have told her that now i have bought her the Ipad she would have to log into her user, the only thing is there is no music in her itunes account nor photos in her I Photo library, i have spent all day trying to find a way to "share" but no luck,
    Please help i`m going mad!
    Surely we could just share these...?
    I need step by step instructions please someone send me a link on "how to share pics and music!"

  • Three types of restaurant menus with same dishes but different prices.

    Hi,
    I have to artwork three types of menus for a small restaurant chain. These menus have the same dishes and same background but different prices per restaurant. I will be sending three high res PDFs to print and would like to know if there is a way of doing this without creating three versions of the menues. I know I could create layers and have a layer per restaurant with the text boxes on, turning off and on as I create my PDFs for print but can I have text within the text block that I can turn on and off? Two text blocks, one with prices and one without, is not an option becaues the text all needs to run round together. The reason for this is if a dish needs to be amended it only has to be done once to the master dish. I hope this makes sense.
    Many thanks!

    Hi Guys,
    Thanks very much for your speedy responces!
    With regard to the data merge method I am not sure this would work for me because there is a lot of text and I need them to flow from page to page so would need all the text and prices in one text block (I hope I have understood your method correctly MW Design!). I have just had a look at the Conditional Text method and that seems as though it might work for me but one issue I might have is if one dish is removed form a menu all together then the text will run up from another block. I am sure there is a way once I have the master menu done to force the text to the next text block after the last dish I want on that page and then enlarge the text block a little to accommodate any movement of the dishes on that page, I will look into that!
    Thanks very much for your help.
    PS InDesign never ceases to amaze me!!

  • How can I let firefox save usernames/passwords for multiple subdomains that use the same username but different passwords?

    on a particular website that has sub domains I have multiple accounts with the same name but different password. Firefox seems only able to save one of them, because they are on the same site.

    "Things"?  What things?  Apps for keeping track of when to change cat litter?  30 different versions of "twinkle, twinkle little star" played by everything from punk rockers to Gregorian chant?  Videos on the best way to make Christmas cake?

  • When importing songs of a same album but different artist iTunes will separate the artists. How can I bring all together in the same album?

    When importing songs of a same album but different artist iTunes will separate the artists. How can I bring all together in the same album?

    Generally setting a common Album Artist will fix things. For deeper problems see Grouping tracks into albums.
    tt2

  • OBIEE report based on same criteria but different view based on filter

    Hi,
    I am trying to create a report in OBIEE 11.1.1.5 where In the same report using the same criteria, I can have different views which applies different filter.
    Suppose, I have a report criteria as
    Dim1, Dim2, Measure1, Measure 2.
    I want to create two pivot view based on the same data.
    One view will be showing data Dim1="Value1". The other view is duplicate of this view but will show data Dim1="Value2".
    Is it possible in OBIEE?
    basically what I want is work on the same dataset but different representation and show them in the same report. Please share your opinion.
    Regards,
    Tanveer.

    Hi,
    You create a new dim dummy column in criteria and in presentation level create new pivot table view use this dummy dimension column and filter with dim1=value2.
    give updates on this.
    Mark if Helpful/correct.
    Thanks.

  • HT3819 How do I share my itunes library with my mother on the same computer, but different accounts?

    How do I share my itunes library with my mother on the same computer, but different accounts?
    My mother and I share a desktop computer (apple) and we have seperate itunes accounts. How do we share accounts?

    iTunes Home Sharing now works between users on same computer - https://discussions.apple.com/thread/3865597
    You could set up two completely separate libraries and share music via Home Sharing.
    iTunes: How to share music between different accounts on a single computer - http://support.apple.com/kb/HT1203 - relocating iTunes' media folder to a shared area but leaving separate library files - extra tip at https://discussions.apple.com/message/17331189
    Chris CA's instructions on sharing one iTunes music library between multiple user accounts - https://discussions.apple.com/message/8974074 - Multiple users using a single library file - similar post at: https://discussions.apple.com/thread/3753008
    Suggestion by Turingtest for multiple users and one library - http://discussions.apple.com/message/9117622 - use smart playlists and tags to isolate groupings.
    Discussions on using purchases from multiple AppleIDs in one iTunes library - https://discussions.apple.com/message/19543804

  • How can i share photos on the same mac but different users?

    how can i share photos on the same mac but different users? we have different iphoto acounts and just want to be able to look under users in the finder and view another users iphoto.

    You may try moving ur librarie to the folder /Users/shared if and link it to iphoto from there
    You may locate and link libraries from arkiv-->change library in iphoto

  • LinkedHashMap problem (Same key but different value)

    Dear Friends,
    There is problem in LinkedHashMap for same key but different values.
    I want both values of same key as Output.
    Plz help me from an example code & it's output
    LinkedHashMap<Object, LinkedList<Object>> linkhash = new LinkedHashMap<Object, LinkedList<Object>>();
    LinkedList<Object> ll6 = new LinkedList<Object>();
              LinkedList<Object> ll7 = new LinkedList<Object>();
              LinkedList<Object> ll9 = new LinkedList<Object>();
    objectName="Listitem";
              ll6.add("id\tlisti");
              ll6.add("tag\tlistcell");
              ll6.add("tag\tlistcell");
              linkhash.put(objectName, ll6);
              System.out.println("List is "+linkhash);
              objectName="Listcell";
              ll7.add("id\tlistc");
              ll7.add("label\tCEO");
              linkhash.put(objectName, ll7);
              System.out.println("List is "+linkhash);
              objectName="Listcell";
              ll9.add("id\tlistc1");
              ll9.add("label\tNKC");
              linkhash.put(objectName, ll9);
              System.out.println("List is "+linkhash);
    output is
    List is {Listitem=[id     listi, tag     listcell, tag     listcell]}
    List is {Listitem=[id     listi, tag     listcell, tag     listcell], Listcell=[id     listc, label     CEO]}
    List is {Listitem=[id     listi, tag     listcell, tag     listcell], Listcell=[id     listc1, label     NKC]}
    I want output as
    List is {Listitem=[id  listi, tag  listcell, tag  listcell],Listcell=[id   listc, label CEO], Listcell=[id     listc1, label  NKC]}
    Plz help me
    Thanks Friend
    Edited by: kkcnkc on Apr 1, 2009 6:47 AM

    Double post. Locking.

  • JSR 172: error while invoking methods of same signature

    Hi
    I am facing a peculiar problem which is not making sense to me. This is what I have done:
    1. Written a simple web service that has two methods: sayHello and sayHellToMe. Both these methods have same signatures. They do not take in any parameter and return a string.
    2. Deployed this web service (document/literal) type on Axis 1.2
    3. Generated the stub classes from the wsdl file using Sun Wireless Toolkit's Stub Generator
    4. I have now written a MIDlet that uses this stub class to invoke both the methods one after the other.
    I enabled SOAPMonitor on Axis and saw the SOAP Request and SOAP Response messages. I observed the following:
    1. In the first method: sayHello - everything works fine (with a few tweaks in the Stub class)
    2. However, while invoking the second method sayHelloToMe, the SOAP Body tag in the SOAP Request does not contain any method name. I checked out the Stub class, the qnames and the types are all correct..
    I also realized that this behavior is seen only when I have methods with the same signature in the web service. Any idea why this might be happening? It seems like a very weird problem.
    Any help in this regard will be greatly appreciated.
    Thanks,
    Arati

    The 'numeric or value error' is one we have seen many times. The problem has been identified and fixed. Refer to this thread for more information.
    Issue with DB Adapter - ORABPEL-11811

  • Importing files with same name but different extensions

    Hope I will be clear enough.
    Lets say that instead of sending a file from Lightroom to an external editor, I open it directly in Photoshop.
    When I'm done, I save the edited photo using the same name but in a different file format : IMG_1333.cr2 > IMG_1333.psd or IMG_1333.tif, and selecting the same folder location.
    Then, I come back into Lightroom and synchronise the folder.
    Why is the knew version of the picture not showing up beside the original file, despite the different extension ?
    I notice that the different extensions ( .psd or .tif ) are recorded in the sidecar files field in the Metadata panel.
    Of course, everything works fine if the file name is modified ( or just by selecting the "copy" option in Photoshop's "save as" dialog box ). Lightroom synchronise dialog shows the new photo to import.
    So, why is Lightroom not making a difference between files with the same name but different format extensions ?
    Thanks for any hint :-)
    Gilles.

    Gilles-
    I think your problem is likely that you have the option to stack the copy with the original turned on. First, right-click on one of these photos and go to the stacking menu. If Unstack is not grayed out then you have a stack -- select Unstack to reveal all copies.
    To change the automatic stacking of edited copies from Photoshop, when you next choose to edit a file, in the bottom left corner of the dialog is the check box for unstacking. Clear it, and that choice should "stick" until you change it again.
    Hope this helps!
    Tony

  • APM how to create APM application group for same application but different application paths

    Hi all,
    We have few applications which are of same name but different application path.
    Please check the screenshot. When we create different application groups using APM wizard, we still get errors mentioning the conflict. How to resolve this issue.
    Thanks
    Manish
    Manish

    I cannot see any screenshot here, what do you mean same application name but different path?

Maybe you are looking for

  • Template for ABAP programs

    Hi all. I've implemnted the following soultion for our SAP system. Go to TCODE CMOD, Create a new Project like ZSE38 as follows. Check the 'Enhancements Assignments' Radio button, click create and add SEUED001 ( for Editor ) now SAVE, click on Compon

  • Problem Importing Photos from Aperture 3 into iPhoto '11

    I store my photos in Aperture 3, but import them into iPhoto to create calendars, cards, etc. I usually work with RAW or high resolution JPG images in Aperture. However, when I import these into the new iPhoto '11, it automatically converts my RAW im

  • How to get ME23 screen using selection-screen

    Hi, I am trying to get the ME23 screen using selection-screen with following code. select-options: purordno for ekko-ebeln NO intervals. SUBMIT SAPMM06E VIA SELECTION-SCREEN . But at the time of execution i got this error "INCORRECT PROGRAM TYPE WITH

  • Automatic red eye correction

    How canI disable automatic red eye correction?

  • Mail crashes repeatedly after power outage

    Hi folks. This evening we had a power outage that shut down my computer without warning (no, no UPS; we're in a temporary rental house, and I didn't bring the UPS, which was probably dumb). Ever since, when I try to start up Mail, it will open, remai