Java interface as method arg question.

Hello,
Imagine that I have the following two interfaces and their associated classes:
AI, AC, FooI, FooC
where AC and FooC implements the interfaces AI and AC respectively. Assume than that FooI has contains only the following method:
public void doIt(AI arg);
So far so good. Now assume that FooC attempts to implement the method in it's interface like so:
public void doIt(AC arg);
The java compiler complains thusly:
C:\moment\javatest>javac AC.java AI.java FooC.java FooI.java
FooC.java:1: FooC should be declared abstract; it does not define doIt(AI) in FooC
public class FooC implements FooI
I was surprised by this result. Since AC honors AIs contract, why is the compiler complaining. If someone could explain the reasoning behind the error, I'd really appreciate it. Thanks in advance.
-exits

AC may be an implementation of AI, but not every implementation of AI is AC.
The FooI interface is essentially insisting that the method work on every implemenation of AI. If you create a method that works only on a particular subset of AIs, namely ACs, then you haven't really implemented the method as specified.

Similar Messages

  • Java Interfaces without methods.

    hi,
    I am new to java... can anyone list me which are the interfaces with no methods in java.
    thanks in advance...

    Are you looking for marker interfaces?yes you got it... send a link..Hmmm ok then take this assignment ;). U to find these marker interfaces in Java SDK Serializable, Remote, Cloneable, EventListener, SingleThreadModel etc.
    If you want a bigger list then follow the below link and search thru all the packages.
    http://java.sun.com/javase/6/docs/api/
    Good luck.

  • Java Interface Question.

    There are classes in the Java SDK, such as the Interface:
    org.w3c.dom.Document
    that have factory methods in them that carry out actual operations.
    But how can this be possible, because when I program an interface:
    public interface test {
    public void setString(String s);
    It will only compile thus, with no implementation on the method signatures?
    How do Java interfaces with factory methods to this?
    org.w3c.dom.Node is another one. Where does the functionality/method implementation
    come from?

    public interface MyInterface {
         public void method1();
    class MyImplementation implements MyInterface {
         public void method1(){
    public class MyFactory {
         public static MyInterface createMyInterface(){
              return new MyImplementation();
    public class Test{
               public static void main(String args[]){
                      MyInterface x=MyFactory.createMyInterface();
                      x..method1();
    }Now can you understand this? Assume all These classes are separate classes. This is not a problem with inner classes. Before make a reply, try to understand it or post a reply as saying it is not clear rather than posting this kind of post.

  • Java Interface does not accept method that passes ArrayList...Why?

    Java Interface does not accept method that passes ArrayList...Why?
    for example...
    public interface Interface extends java.rmi.Remote
    public ArrayList getSomething(String ID) throws java.rmi.RemoteException;
    Why is this not acceptable?

    Java Interface does not accept method that passes ArrayList...Why?for example...
    ALSO:
    You are not 'passing' ArrayList, you are returning it.
    If you are 'passing' anything, it is String.
    ~David

  • Interfaces and methods of Object class

    JSL 2.0 states the following
    If an interface has no direct superinterfaces, then the interface implicitly
    declares a public abstract member method m with signature s, return type r,
    and throws clause t corresponding to each public instance method m with
    signature s, return type r, and throws clause t declared in Object, unless a
    method with the same signature, same return type, and a compatible throws
    clause is explicitly declared by the interface.
    But the following codes produces empty output
    package test;
    import java.lang.reflect.Method;
    public class TestIterface {
        public static void main(String [] args){
            Method [] methods=Y.class.getMethods();
            for(int i=0, n=methods.length;i<n;i++)
                System.out.println(methods);
    interface Y{
    What are the reasons of such behaviour?

    then the interface implicitly declares a public abstract member method
    "Implicit" means that it's implied that the interface declares those methods; unlike java.lang.Object, there is no interface from which all other interfaces descend. All interfaces at the "top" of the inheritance hierarchy are implied to expose at least the same methods as Object.
    Hope this helps...

  • Java.sql.Blob method setBinaryStream?

    Hi,
    I've been trying to use the java.sql.Blob methods instead of the "Oracle Extensions" so that people w/o Oracle (using MySQL etc.) can still use my code.
    Problem: trying to get the OutputStream to write to the Blob. As of JDK1.4, java.sql.Blob has a method to do this, setBinaryStream. Unfortunately, calling this in Oracle JDBC (tried it in both thin and OCI version) throws an SQLException (Unsupported feature).
    Sample code:
    //Assume we already have a connection to the database, over either OCI or thin.
    //Assume a Statement stmt created from the connection.
    //Assume a table BlobTable with 2 fields : id (number) and data (blob).
    public void uploadBlob(byte [] theBytes){
         try{
         stmt.executeUpdate("INSERT INTO BlobTable (id, data) VALUES (1,empty_blob())");
         ResultSet rs = stmt.executeQuery("SELECT data FROM BlobTable WHERE id=1 FOR UPDATE");
         if (rs.next()){
    java.sql.Blob blob=rs.getBlob(1);
         OutputStream out=blob.setBinaryStream(0);
         //Next line never printed - error thrown.
         System.out.println("Got Stream");
         catch(Exception e){e.printStackTrace();}
    //End code
    Am I doing something wrong? Or is there simply no way to write to a Blob without using the extensions?
    None of the docs (examples, guides, etc) make any mention of this, although the JDBC dev guide does mention that the similar method in PreparedStmt only works over OCI.
    Thanks,
    Dan

    Hi lancea,
    It's been a while since this thread was active, but I have a related question.
    Is there a comprehensive list of changes between JDBC 3 and JDBC 4 that makes application not work any more, such as this setBinaryStream issue or the CallableStatement/Named parameters issue that we stumbled upon. We would like to address these issues proactively and not find out about them in production, since we're upgrading from jdk1.4 to jdk6. Oracle has provided us with their changes regarding database versions, but have been less forthcoming with JDBC spec version changes.
    Thanks in advance,
    Thomas Auzinger

  • How can we call java control source methods within jsp

    Hi guys!
              How can we access java control source methods that are defined in java control projects within jsp.I am getting error when I tried to call java control source's methods in scriptlet of JSP page.Any help/suggestion is appreciated.
              Thanks
              -Chandu

    Uh, what?
    (And you are sure that it's not a Weblogic-specific question?)

  • Using java.lang.reflect.Method.invoke on a static method?

    This is probably a FAQ, but I am finding it impossible to construct a search which answers this question for me.
    How do I call java.lang.reflect.Method.invoke on a static (e.g. class) method? Is it even possible?
    Thanks,
    dwh

    Is this of any help?
    http://www.esus.com/javaindex/j2se/jdk1.2/javalang/reflection/reflection.html
    Cheers,
    Joris

  • Are Java Interfaces 'free'?

    From a performance point of view, are Java interfaces free?
    That is, if I have:
    class Foo
    public void bar() { ... // some code }
    }and I change it to:
    interface Foo
    public void bar();
    class FooImpl implements Foo
    public void bar() { ... // some code }
    }And I call one or other of the Foos like
    Foo foo // A parameter, field or local variable.
    foo.bar();Does calling foo through an interface add any overhead that calling it direct in the first example not? As I understand it, all methods are 'virtual' in Java, so it should perform the same in either case.
    Thanks for any of your thoughts.
    Rupert

    rupertlssmith wrote:
    YoungWinston wrote:
    The Second Rule of Program Optimization (for experts only!): Don't do it yet.&#148;
    - Michael A. Jackson
    Basically, don't worry about it. Worry about writing clear, correct, object-oriented code.
    Wierdly enough, in the long run, that is more likely to help than anything else you can do, should (and if) you ever need to worry about optimization in the future.
    WinstonThanks for the advice. I can write good clear OO code. I am now at the future and worrying about optimization, so have made it past the second rule!Then you exactly know where your bottleneck is from the profiler you've used. Did it tell you that your interfaces are the bottleneck? If so, why do you even bother to ask here?

  • Deprecated interfaces and methods

    We have a weblogic time service that utilize a lot of
    deprecated interfaces and methods such as
    ScheduledTriggerDef, TimeServicesDef etc. Although the time
    service runs in the WLS 7, it is a big concern to me
    that it uses so many deprecated interfaces or methods.
    I am just wondering how I can replace them with non-deprecated ones

    Mark,
    I have a question about the API.
    From the documentation and the API docs it is not clear how to schedule
    a callback to be called just once ASAP.
    We use the deprecated Timer service to execute long running operations
    on the Weblogic thread pool and want the operation to execute only once
    and start as soon as there is a thread available.
    It is not clear what will happen in case a task is scheduled to be
    executed only once and the time for that execution has passed ( 5 ms ago).
    I'd appreciate the clarification.
    Thanks,
    Dejan
    Mark Griffith wrote:
    It will run because it is only deprecated. You should at some point
    "rewrite", but the rewrite is not that big of a deal. There maybe some
    slight differences in timers, since we moved to jmx interfacs, but the
    scemantics should be very very close.
    Attached is an example that will run in the 8.1 sample environment.
    cd to $WLS_HOME
    (On my box it is /bea/wls81/weblogic81/)
    cd samples/domains/examples/
    setExamplesEnv.sh
    cd ../../server/examples/src/examples
    ../examples/src/examples 201$ pwd
    C:/bea/wls81/weblogic81/samples/server/examples/src/examples
    cp jmxTimerEar.zip .
    jar xvf jmxTimerEar.zip
    cd jmxTimerEar
    ant
    And it should build for you.
    Cheers
    mbg
    "Eric Sundberg" <[email protected]> wrote in message
    news:[email protected]..
    We have a weblogic time service that utilize a lot of
    deprecated interfaces and methods such as
    ScheduledTriggerDef, TimeServicesDef etc. Although the time
    service runs in the WLS 7, it is a big concern to me
    that it uses so many deprecated interfaces or methods.
    I am just wondering how I can replace them with non-deprecated ones

  • Interfaces declare methods that one or more classes may or may not implemen

    Interfaces declare methods that one or more classes may or may not implement.
    true or false?

    Encephalopathic wrote:
    If you want to appear to be more than just someone scrounging for someone else to do their homeworkHe/she is what they is
    [http://forum.java.sun.com/thread.jspa?threadID=5292343]
    [http://forum.java.sun.com/thread.jspa?threadID=5283461]
    [http://forum.java.sun.com/thread.jspa?threadID=5283412]
    [http://forum.java.sun.com/thread.jspa?threadID=5279385]

  • Why java allow start() method only once for a thread

    Hi ,
    Why java allows start method only once for thread . suppose
    Thread t = new Thread();
    t.start();
    say at later stage if again we call t.start() IllegalStateException is thrown , even though isAlive method returns false.
    Hence the question , why start() method is allowed only once.If you need start a thread , we need to create a new instance.

    Really. Why do you think that? Do you have any evidence? It is one of the first things I would think of, personally.Considering that the Thread API doesn't allow you to specify a stack address (only stack size), I think it demonstrates they wanted to remove that capability from their Thread API all together. That missing "capability" makes me believe they want me to believe it's not something I need to worry about when using their API... I think the exact semantics of the Thread class and its methods were driven by how to make it most understandable and usable for their customers. I'm certain this issue was one of many that was given considerable thought during the design and implementation of the JVM and the underlying runtime classes.
    Do I have any evidence? No. But if you can point me at some first-hand information on this, I'd love to read it. Most of what I've found is second or third hand accounts. (and I mean that sincerely, not as a smart-ass remark or rebuke of your comments).
    On the one hand you seem to think the Java API designers are idiots, on the other hand you think that they should be. I can't make it out.I thought my position was that the Java developers were talented enough to implement platform in whatever way their API called for; hence, the designers made a choice about how they wanted their API to be used by their customers. They decided which capabilities they wanted to include or exclude, and created an API that was consistent with their vision for this technology. While I'm certain technical limitations had an effect on the API design, I certainly don't think the API was dictated by the them.
    I think the current design of the Java Thread API was a reflection of their vision to make Threading easier and more accessible to Joe Programmer, not limitations in the implementation. I never said it was wrong or that I could do better... I just said I think they could have done something different if they decided it would have made for a better customer experience. But hey, maybe I'm wrong.

  • Mediator To Spring Error-Could not convert from java interface to interface

    Hi,
    I have a requirement to using a Spring component and my composite application would be File Read -> Mediator -> Spring Component -> File Write.
    I have to read a file and using mediator map the same to the Spring input and write the Spring component output to a file.
    I have created a Java interface ( Package Name - transformtospring , Interface Name - TransformInterface) and also created a Java Class ( TransformImpl ) which implements the Interface in this package. Saved all these artifacts in SCA-INF/src folder of the application.
    My Spring Bean configuration file is as follows ( saved the file in the same folder as composite.xml )
    <?xml version="1.0" encoding="windows-1252" ?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:sca="http://xmlns.oracle.com/weblogic/weblogic-sca"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-2.5.xsd http://xmlns.oracle.com/weblogic/weblogic-sca META-INF/weblogic-sca.xsd">
    <!--Spring Bean definitions go here-->
    <bean class="transformtospring.TransformImpl" name="TransformBean"/>
    <sca:service name="TransformService" target="TransformBean"
    type="transformtospring.TransformImpl"/>
    </beans>
    I have created a Spring Context which uses the above Spring Configuration. When i tried to map the mediator output to Spring , i'm getting an error shown below.
    " Could not convert from java interface to interface type wsdl . Exception=java.lang.ClassNotFoundException transformtospring.TransformImpl "
    Please do let me know where exactly i'm doing wrong.
    Regards,
    Sri.

    Hi All,
    I could able to work this one out now !!!
    But i'm having an issue mapping the input to this service. The method signature for the service is as follows:
    public byte[] processData(byte[] input) throws Throwable{
    So the input for this Service is a byte array. Now i'm mapping the data from a File Input ( Read File - opaqueElement ) to this service directly ( using mediator ).
    Now when i have looked into the message in the Enterprise Manager, following is the message structure from Read File input to the service.
    <message>
    <properties>
    <property name="tracking.compositeInstanceId" value="10009"/>
    <property name="tracking.ecid" value="bcd04297e25136e7:4869a9c:13316255efc:-8000-0000000000001f79"/>
    <property name="tracking.conversationId" value="TJ9PCcbtu3S0DA0GuxsGx13RYUb1NxHNndfk2PC8ukk."/>
    </properties>
    <parts>
    <part name="parameters">
    <ns0:processCollaboration>
    <arg0>PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48bnMwOkFkZDJJbnB1dCAgeG1s bnM6eHNpPSdodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZScgeG1sbnM6 bnMwPSd1ay5jby5qZHdpbGxpYW1zLkFkZDJJbnB1dCcgeHNpOnNjaGVtYUxvY2F0aW9uPSd1ay5j by5qZHdpbGxpYW1zLkFkZDJJbnB1dCByZXF1ZXN0LnhzZCcPG5zMDpudW0xPjEwPC9uczA6bnVt MT48bnMwOm51bTI+MTY8L25zMDpudW0yPjwvbnMwOkFkZDJJbnB1dD4=+</arg0>
    </ns0:processCollaboration>
    </part>
    </parts>
    </message>
    and the corresponding response message ( No output ) back from the service is:
    <message>
    <properties>
    <property name="tracking.compositeInstanceId" value="10009"/>
    <property name="tracking.ecid" value="bcd04297e25136e7:4869a9c:13316255efc:-8000-0000000000001f79"/>
    <property name="componentName" value="ProcessCollab"/>
    <property name="tracking.conversationId" value="TJ9PCcbtu3S0DA0GuxsGx13RYUb1NxHNndfk2PC8ukk."/>
    <property name="compositeDN" value="default/CollaborationToSpring!1.0*soa_a8da1da7-f98f-4935-8d20-da9e7bc003cc"/>
    </properties>
    <parts>
    <part name="parameters">
    <processCollaborationResponse>
    <return/>
    </processCollaborationResponse>
    </part>
    </parts>
    </message>
    I have included System.out statements in my Java class , but its not printing anything in the logs.
    I'm under the impression that the underlying infrastructure ( mediator ) transparently encodes and decodes data from base64Binary to java byte array. So could anyone help me on this !!!
    Regards,
    Sri.

  • Could not convert from java interface to interface type wsdl ??

    i have a problem wheni have a problem when i develop bpel using mediator and wire to ejb service. When the mediator wire to ejb service, i found the error : Could not convert from java interface to interface type wsdl.... How to solve the problem?

    I followed the case closely (with the same name of classes, methods, etc), but still get the error: “Could not convert from java interface to interface type wsdl.Exception=nl.amis.calculator.Calculator”. I created a Java class to test the lookup and function correctly. However, when I try to wire a Mediator to this Reference, I run into an Interface Conversion Error. I’ve included the line javaInterface = “nl.amis.calculator.Calculator” in file composite.xml, but still get error. Could you help me?

  • Any good article on Java Interface usage principle?

    Hi All
    I find Java interface is quite good concept, but some expert mentioned in some article, "Don't over use it".
    Just wonderring anyone can point me to some good article on the internet on In what kind sceniaro we need use Interface, in which case we'd better not use it.
    Thanks in advance.
    Steven

    Then how do you explain some gurus said" don't overuse interface"?I explain it thus:
    (a) it doesn't actually contradict what the article says
    (b) 'don't overuse interfaces' is a tautology: it doesn't actually say anything very useful.
    On the other hand there's no reason why "some gurus" can't disagree with Holub. I disagree myself to a large extent. You can define your entire API as interfaces, but then you're committed to all kinds of factory methods, and provision of secret implementation classes, etc. This can get pretty tedious pretty quickly. And, somewhere or other, you must have at least one actual class, so that you can have either a static method or a constructor, so you can get hold of your initial factory, or factory builder, or factory builder factory, or factory builder factory builder, or wherever it is that you want to start.
    I've used frameworks where there were four different implementation classes for the same interface. Never did find out why. Something wrong somewhere.
    When you can keep your base classes stable, I don't see a reason not to use them. 'Base class fragility' is all that Holub is really complaining about, and there are lots of solutions to that, such as 'don't' for a start. Java is chock full of stable base classes.

Maybe you are looking for

  • Can't install or uninstall itunes itunes 64.msi error

    Can't install or uninstall itunes itunes 64.msi error - does anyone have a fix? The itunes64.msi cannot be found in the temp sub-folder it was originally installed in. I believe the System Mechanic cleaned out the temp files and now I can't install o

  • How to rotate pencil mark in Acrobat X?

    How to rotate pencil mark in Acrobat X? When I am coping pencil mark between pdfs it auto-rotates into horizontal position. Thanks in advance. Greg

  • How do I sort by capture time?

    I have a full day of clips from 2 cameras, how do I arrange by capture time within imovie...thanks

  • System Preferences gone wrong

    Currently i've set my wallpaper to my own pictures, and expose settings. After a while, the wallpaper turns blank (blue) by itself and the expose suddenly didnt work. i have to set it again in order to work. pls help.

  • Different image behavior within same document

    Hello, I'm making a catalog for which I got photos  from various sources but mainly white background JPGs. I noticed that  when I place them in InDesign document some of them have transparent  background and some not. I checked in photoshop and backg