Help on Incompatible types

Sample 1:
public interface I<T extends I<?>>
  I<? extends I<T>> m1 ();
public class Z<T extends I<?>> implements I<T>
  public I<? extends I<T>> m1 ()
    return m2();
  protected I<? extends I<T>> m2 ()
    return null;
javac Z.javacompiled with no problems
Sample 2:
public interface I<Tx, T extends I<Tx, ?>>
  I<Tx, ? extends I<Tx, T>> m1 ();
public class Z<Tx, T extends I<Tx, ?>> implements I<Tx, T>
  public I<Tx, ? extends I<Tx, T>> m1 ()
    return m2();
  protected I<Tx, ? extends I<Tx, T>> m2 ()
    return null;
javac Z.javaZ.java:5: incompatible types
found : I<Tx,capture of ? extends I<Tx,T>>
required: I<Tx,? extends I<Tx,T>>
return m2();
^
1 error
Well... can anyone help with this? Or at least some explanations why adding second generic generates this problem?

The problem is in the recursion, not in the second type argument. If you changed your first interface from
    public interface I<T extends I<?>> {} to
    public interface I<T extends I<T>> {} you would run into the same error message. For sake of clarity let's discuss the issue using your first example in a slightly simplified form:
    public interface I<T extends I<T>> {}
    public class Z<E>
      public I<? extends I<E>> m1 ()
        return m2();
        /* error: incompatible types
           found   : I<capture of ? extends I<E>>
           required: I<? extends I<E>>
           return m2();
                    ^
      protected I<? extends I<E>> m2 ()
      { return null; }
    }The error message is not awfully helpful, because the "E" is different in both types.
Method m2 returns a reference of type I<capture of ? extends I<E>>, where E extends I<capture of ? extends I<E>>, that is, it returns a concrete instantiation of the interface, namely I<SomeType> with a type that extends I<SomeType> with a type that extends ... continued recursively.
On the other hand, method m1 is supposed to return a reference of type I<? extends I<E>>, where E extends I<? extends I<E>>, that is, it returns a wildcard instantiation of the interface, namely I<? extends I<SomeType>> with a type that extends I<? extends I<SomeType>> with a type that extends ... continued recursively.
And here is the point: The first construct leads to a concrete instantiation like a List<List<List<String>>>. The second construct lead to a recursive wildcard instantiation like List<? extends List<? extends List<?>>>. As soon as the wildcard appears on a nested level, the types are no longer compatible.
It's like assigning a List<List<String>> to a List<List<?>>. It's not permitted because the first is a list of string-lists and the second is a list of mixed-lists. You cannot assign one to the other.
In your example, changing
    public interface I2<Tx, T extends I2<Tx, ?>> to
    public interface I2<Tx, T extends I2<?, ?>>might do the trick.
(As usual, ignore the annoying additional angle brackets.)

Similar Messages

  • Incompatible types error....plzz help

    the code is
    import java.util.*;
    class a{
    public static void main(String args[]){
    LinkedList list = new LinkedList (  ) ; 
    list.add ( "shiva" ) ; 
    list.add ( "java" ) ; 
    list.add ( "world" ) ; 
    String [  ]   str = list.toArray ( new String [ list.size (  )  ]  ) ;
    }}the error is
    C:\Documents and Settings\Sumit\Desktop>javac a.java
    a.java:11: incompatible types
    found : java.lang.Object[]
    required: java.lang.String[]
    String [  ] str = list.toArray ( new String [ list.size (  )  ] ) ;
    ^
    Note: a.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    1 error
    i am not getting what's wrong with it

    i am not getting what's wrong with itYou're not going to like this advice, but still you must learn to help yourself. If you've not done so, please look at the API on the LinkedList toArray method. If it doesn't make sense to you, then ask specific questions about what in the API you don't understand.

  • Incompatible types with generics problem

    Hi,
    I get a mysterious compiler error:
    C:\Documents and Settings\Eigenaar\Mijn documenten\NetBeansProjects\Tests\src\tests\genericstest.java:26: incompatible types
    found : tests.Store<T>
    required: tests.Store<T>
    return store;
    1 error
    BUILD FAILED (total time: 0 seconds)
    in the following code:
    class Supply<T extends Supply<T>>{}
    class Store<T extends Supply<T>>{ }
    class A<T extends Supply<T>>{
        private Store<T> store;
        class B<T extends Supply<T>> {
            public Store<T> getStore(){
                return store;                         <-- compiler error!
    }Any help would be greatly appreciated.
    Edited by: farcat on Jan 13, 2009 1:23 PM

    Note that the type parameter T used to define class B is not the T used to define class A. What you wrote can be more clearly written:
    class Supply<T extends Supply<T>>{}
    class Store<T extends Supply<T>>{ }
    class A<T extends Supply<T>>{
        private Store<T> store;
        class B<U extends Supply<U>> {
            public Store<U> getStore(){
                return store;
    }Which produces the more readable error message:
    A.java:10: incompatible types
    found   : Store<T>
    required: Store<U>
                return store;B, being a nested, non-static class is already parameterized by T:
    class Supply<T extends Supply<T>>{}
    class Store<T extends Supply<T>>{ }
    class A<T extends Supply<T>>{
        private Store<T> store;
        class B {
            public Store<T> getStore(){
                return store;
    }

  • Incompatible types in CMP .. How to read RAW

    MY CMP bean has a few CMP fields which are of type byte[] in the database i
    created dbfields having RAW datatype. Deployment is Successfull. but when i
    try to create this CMP then the ejbexception is thrown and it is having a
    nested exception SQLException Incompatible types
    Please help

    "LJS Narayana" <[email protected]> wrote in message
    news:[email protected]..
    MY CMP bean has a few CMP fields which are of type byte[] in the databasei
    created dbfields having RAW datatype. Deployment is Successfull. but wheni
    try to create this CMP then the ejbexception is thrown and it is having a
    nested exception SQLException Incompatible types
    Please help

  • Incompatible types in simple odbc statements

    this is my simple code
    import java.sql.*;
    public class QueryApp {
         public static void main(String a[]){
              try{
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   Connection con;
                   con=DriverManager.getConnection("jdbc:odbc:MyDataSource","nik","123456");
                   Statement stat=con.createStatement();
                   stat.executeQuery("Select * from Publishers");
              catch(Exception e){
                   System.out.println("Error:"+e);
    }after this when i compile i get these errors
    QueryApp.java:15: incompatible types
    found   : java.sql.Connection
    required: Connection
                con=DriverManager.getConnection("jdbc:odbc:MyDataSource","nik","123456");
                                                           ^
    QueryApp.java:16: cannot find symbol
    symbol  : method createStatement()
    location: class Connection
                Statement stat=con.createStatement();
                                              ^
    2 errorsCan some body help me on this error as searching on net wasn't fruitfull?

    1) You probably created a Connection class your compiler tries to use instead of java.sql.Connection. I advise to rename your class, or at least use the fully qualified classname for declaring con.
    2) The Connection class you created does not have such a method.

  • Problem with incompatible types

    Can you help me out where the problem is? The Child extends the Iterator<GenericTypeTest> so why the assignment doesn`t work? Thank you in advance
    class GenericTypeTest implements Iterator<GenericTypeTest> {
        public GenericTypeTest() {
            Child a = null;
            Iterator<GenericTypeTest> b = null;
            b = a;
            Set<Child> sa = null;
            Set<Iterator<GenericTypeTest>> sb = null;
            sb = sa; // HERE: COMPILATION PROBLEM
            // (Incompatible types: found: Set<Child> required: Set<Iterator<GenericTypeTest>>)
        public boolean hasNext() {
            return false;
        public GenericTypeTest next() {
            return null;
        public void remove() {
    class Child extends GenericTypeTest {}

    You can only assign from a subtype to a supertype. And the subtype/supertype relationship for generic types isn't what you think it is. Read this FAQ entry for more information, especially the part around the sentence "The prerequisite is that at least one of the involved type arguments is a wildcard."

  • Neophyte: Incompatible Types

    Hi all, new to programming and Java in particular. Here is the code:
    import java.net.*;
    import java.io.*;
    class WHWWW {
         public static void main (String[] arg) {
              URL u = new URL("http://www.google.gov/");
              FilterInputStream ins = u.openStream();
              InputStreamReader isr = new InputStreamReader(ins);
              BufferedReader whiteHouse = new BufferedReader(isr);
              System.out.println(google.readLine());
    Here is the error:
    Incompatible Types
    found: java.io.InputStream
    required: java.io.FilterInputStream
    FilterInputStream ins = u.openStream();
    ^
    Thanks for the help.

    Create one of the subclasses of FilterInputStream
    instead of InputStream. Perhaps BufferedInputStream
    would be appropriate here.
    Whoops. That should have been ]Create one of the subclasses of FilterInputStream instead, using InputStream (as the argument to the constructor). Perhaps BufferedInputStream would be appropriate here.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Incompatible type trouble

    i am writing two classes. first one, StudentImpl.java implementing the Student interface; second one, Engine.class implementing the Auditor class. the interfaces are showed below:
    Student.java:
    import java.util.List;
    public interface Student {
        // Read-only properties
        List<Double> getGrades();
        String getFirstName();
        String getMiddleInitial();
        String getLastName();Auditor.java:
    import java.util.List;
    public interface Auditor {
        // Read-only properties
        double getClassMean();
        double getClassMedian();
        double getClassStandardDeviation();
        List<Student> getStudents();
        // Setting the data file.
        void setFileName( final String fileName );
        String getFileName();
        // Operations
        void load() throws AuditException;
    }In the Engine.class. I'm having trouble with the getStudents() implemented from the Auditor interface, with the following line:
    List<Student> getStudents();
    the return type has to be "Student",
    but my Student.java holds the Student interface, so i have StudentImpl.java to define Student
    but now i seems like i have to change<Student> to <StudentImpl>, but i can't change the interface. i don't know how i am gonna solve this problem, and the compliler keeps saying: incompatible types, i have a headache today! any help will be appreciated!

    for MLRon. the answer is no, but at least the "incompatible type" dissappear. the problem is in the load(), which is used to load the content of a input file:
    public void load() throws AuditException {
            Scanner sc = null;
            try {
                sc = new Scanner(new File(fileName) );
                while(sc.hasNextLine()){
                    this.students.add( new StudentImpl(sc.nextLine()) );
                for(StudentImpl st : students) {
                    for(double g : st.getGrades()) {
                        add(g);
            } catch (Exception e) {
                throw new AuditException(e);
            } finally {
                if(sc != null) sc.close();
        }the error is:
    Driver.java:11: unreported exception AuditException; must be caught or declared to be thrown
    eg.load();
    ^
    i'm pretty sure i did throw an AuditException in the load(), now i got stuck. thanks for your help.

  • Error(86,88): incompatible types; found: java.util.ArrayList

    Hi,
    I'm getting following error :
    Error(86,88): incompatible types; found: java.util.ArrayList, required: com.sun.java.util.collections.ArrayList
    The line JDev is complaining about contains the following code :
    com.sun.java.util.collections.ArrayList runtimeErrors = container.getExceptionsList();
    I really don't have a clue where this error comes from. If I right-click on ArrayList it brings me to the correct declaration.
    Does somebody know what I'm doing wrong?
    Thanks in advance for you help!
    Kris

    Kris,
    try changing the code to :
    java.util.ArrayList runtimeErrors = container.getExceptionsList();apparently container.getExceptionsList() returns a java.util.Arraylist not a com.sun.java.util.collections.ArrayList
    HTH,
    John

  • Incompatible types bug

    I have a problem with one of my method calls. It is saying there is an incompatible type. Here is the error message.
    "BalanceChecker.java": incompatible types; found : java.lang.Integer, required: int at line 28, column 26
    Here is the line line with the problem
    int inputLength = 0;
    inputLength = bc.getLength(input); <=====
    And here is the method
    public Integer getLength(String line)
    int length = 0;
    length = line.length();
    return length;
    Can someone tell me what is incompatible here.

    Hi all,
    I wanted to delete files older than a day, below is the code I have compiled but I am getting incompatible type error....Please any one help me out from this....
    Date t=null;
    Calendar rightNow = Calendar.getInstance();
    rightNow.add(Calendar.DATE-1);
    t = rightNow.getTime();
    Timestamp tm = new Timestamp(t);
    if (tm.before(getTimeStamp(filename)))
    {    del(......) ............................................}
    public static Timestamp getTimeStamp(String fileName) {
    File timestamp1 = new File(fileName);
    return(timestamp1.lastModified());
    }

  • Incompatible types (Generics)

    Can someone explain me please the following message I've got when trying to compile a file?
    incompatible types
    found : java.util.Iterator<E1>
    required: java.util.Iterator<E1>
    If the types are identical, how can they be incompatible???!!!
    Thanks.

    Hello,
    I am stuck, I have a compilation probem. I am trying to compile my torque init class, and it gave an error message says that incompatible types. I am using Vector package to check the index of an element in the array. But the compiler found List instead of vector. Can you please tell me what's wrong.
    // Begin MyProject.java source
    package com.digitalevergreen.mytest;
    import com.digitalevergreen.mytest.om.*;
    import org.apache.torque.Torque;
    import org.apache.torque.util.Criteria;
    import java.util.Vector;
    public class MyProject
    public static void main(String[] args)
    try
    // Initialze Torque
    Torque.init( "C:/Project/torque-3.1/Project.properties" );
    // Create some Authors
    Author de = new Author();
    de.setFirstName( "David" );
    de.setLastName( "Eddings" );
    de.save();
    Author tg = new Author();
    tg.setFirstName( "Terry" );
    tg.setLastName( "Goodkind" );
    tg.save();
    // Create publishers
    Publisher b = new Publisher();
    b.setName( "Ballantine" );
    b.save();
    Publisher t = new Publisher();
    t.setName( "Tor" );
    t.save();
    // Ok. For some reason even though the BaseXPeer doInsert
    // methods return the primary key it is not set in the
    // BaseX save method so we have to "retrieve" these objects
    // from the database or we will get null value exceptions
    // when we try to use them in the book objects and do a save.
    Criteria crit = new Criteria();
    crit.add( AuthorPeer.LAST_NAME, "Eddings" );
    Vector v = AuthorPeer.doSelect( crit );
    if ( v != null && v.size() > 0 )
    de = (Author) v.elementAt(0);
    crit = new Criteria();
    crit.add( AuthorPeer.LAST_NAME, "Goodkind" );
    v = AuthorPeer.doSelect( crit );
    if ( v != null && v.size() > 0 )
    tg = (Author) v.elementAt(0);
    crit = new Criteria();
    crit.add( PublisherPeer.NAME, "Ballantine" );
    v = PublisherPeer.doSelect( crit );
    if ( v != null && v.size() > 0 )
    b = (Publisher) v.elementAt(0);
    crit = new Criteria();
    crit.add( PublisherPeer.NAME, "Tor" );
    v = PublisherPeer.doSelect( crit );
    if ( v != null && v.size() > 0 )
    t = (Publisher) v.elementAt(0);
    // Create books
    Book wfr = new Book();
    wfr.setTitle( "Wizards First Rule" );
    wfr.setCopyright( "1994" );
    wfr.setISBN( "0-812-54805-1" );
    wfr.setPublisher( t );
    wfr.setAuthor( tg );
    wfr.save();
    Book dof = new Book();
    dof.setTitle( "Domes of Fire" );
    dof.setCopyright( "1992" );
    dof.setISBN( "0-345-38327-3" );
    dof.setPublisher( b );
    dof.setAuthor( de );
    dof.save();
    // Get and print books from db
    crit = new Criteria();
    v = BookPeer.doSelect( crit );
    for ( int i = 0; i < v.size(); i++ )
    Book book = (Book) v.elementAt(i);
    System.out.println("Title: " + book.getTitle() );
    System.out.println("Author: " +
    book.getAuthor().getFirstName()
    + " " +
    book.getAuthor().getLastName() );
    System.out.println("Publisher: " +
    book.getPublisher().getName() );
    System.out.println("\n\n");
    catch (Exception e)
    e.printStackTrace();
    // End MyProject.java source
    and this is the error message:
    C:\Project\torque-3.1\src\java\com\digitalevergreen\mytest>javac MyProject.java
    MyProject.java:50: incompatible types
    found : java.util.List
    required: java.util.Vector
    Vector v = AuthorPeer.doSelect( crit );
    ^
    MyProject.java:56: incompatible types
    found : java.util.List
    required: java.util.Vector
    v = AuthorPeer.doSelect( crit );
    ^
    MyProject.java:62: incompatible types
    found : java.util.List
    required: java.util.Vector
    v = PublisherPeer.doSelect( crit );
    ^
    MyProject.java:68: incompatible types
    found : java.util.List
    required: java.util.Vector
    v = PublisherPeer.doSelect( crit );
    ^
    MyProject.java:93: incompatible types
    found : java.util.List
    required: java.util.Vector
    v = BookPeer.doSelect( crit );
    ^
    5 errors
    C:\Project\torque-3.1\src\java\com\digitalevergreen\mytest>
    any help will be appreciated. Thank you in advance.
    Omar N.

  • Hashtable with incompatible types

    HI, I', stuck with this. I'm trying to create a Hashtable wich will use a String as the Key and that will store my own object, but, when I try to get the information from the Hash, the compiler throws this Error:
    tst.java:48: incompatible types
    found : java.lang.Object
    required: Entra_Usuario
    U = usuario.get(usu);
    The code (simplified is)
    public class tst
    public static void main(String[] unused)
         Hashtable usuario = new Hashtable();
    Entra_Usuario U = new Entra_Usuario(...Some parms);
         usuario.put(usu,U);
         try
              while((ra = reg.readLine()) !=null)
              ... get data from fiel
                   usu= somthing from file
                   U = usuario.get(usu); <=== Here is where the compiler complains
                   if (U== null)
                        U = new Entra_Usuario(... );
                        usuario.put(usu,U);
                   else
                        U.update( ..... )
         } catch (Excep...          
    And Class Entra_Usuario is defined as:
    public class Entra_Usuario
         String Fecha_Ini=null;
         String Fecha_Fin=null;
         String Hora_Ini=null;
         String Hora_Fin=null;
         String IP=null;
         String Usuario=null;                
         public Entra_Usuario(some parms ...)
              public void Update(.. some parms .)
    Thx ni advance for your help
    Regards Alejandro

    you have to cast it :
    U = (Entra_Usuario)usuario.get(usu);

  • Incompatible type found

    Gurus,
    I'm getting the following error and hope you could help. It's complaining about code in my AM (in bold). Any ideas?
    Error(281,41): incompatible types; found: oracle.jbo.Row, required: acctmap.oracle.apps.spl.am.server.UserRespVORowImpl
    AM code:
    UserRespVOImpl reqVO = (UserRespVOImpl)findViewObject("Sysadmin");
    if(reqVO!=null)
    Integer userid = new Integer(tx.getUserId());
    reqVO.initUserRespVO(userid);
    reqVO.reset();
    UserRespVORowImpl row = reqVO.next();
    String priv = (String)row.getSysadmin();
    VO code:
    public void initUserRespVO(Integer txUserId)
    setWhereClauseParams(null); //Always reset
    setWhereClauseParam(0,txUserId);
    executeQuery();
    // return Sysadmin;
    }

    Hi Sreese,
    Change your code to ...
    reqVO.reset();
    UserRespVORowImpl row = *(UserRespVORowImpl)* reqVO.next();
    String priv = (String)row.getSysadmin();
    Thanks
    --Anil                                                                                                                                                                                                                                                                                                                                                                   

  • Need Help with data type conversion

    Hello People,
    I am new to java, i need some help with data type conversion:
    I have variable(string) storing IP Address
    IPAddr="10.10.103.10"
    I have to call a library function which passes IP Address and does something and returns me a value.
    The problem I have is that external function call in this library excepts IP Address in form of a byte array.
    Here is the syntax for the function I am calling through my program
    int createDevice (byte[] ipAddress).
    now my problem is I don't know how to convert the string  IPAddr variable into a byte[] ipAddress to pass it through method.

    Class InetAddress has a method
    byte[]      getAddress() You can create an instance using the static method getByName() providing the IP address string as argument.

  • Incompatible types - found java.lang.String but expected int

    This is an extremely small simple program but i keep getting an "incompatible types - found java.lang.String but expected int" error and dont understand why. Im still pretty new to Java so it might just be something stupid im over looking...
    import java.io.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class Lab
    public static void main(String []args)
    int input = JOptionPane.showInputDialog("Input Decimal ");
    String bin = Integer.toBinaryString(input);
    String hex = Integer.toHexString(input);
    System.out.println("Decimal= " + input + '\n' + "Binary= " + bin + '\n' + "Hexadecimal " + hex);
    }

    You should always post the full, exact error message.
    Your error message probably says that the error occurred on something like line #10, the JOptionPane line. The error is telling you that the compiler found a String value, but an int value was expected.
    If you go to the API docs for JOptionPane, it will tell you what value type is returned for showInputDialog(). The value type is String. But you are trying to assign that value to an int. You can't do that.
    You will need to assign the showInputDialog() value to a String variable. Then use Integer.parseInt(the_string) to convert to an int value.

Maybe you are looking for