Results 1 to 4 of 4
  1. #1
    bflhr673 is offline Member
    Join Date
    Jul 2010
    Posts
    4
    Rep Power
    0

    Default incompatible types found object expect integer

    i have a simple program that on compile gives the error
    ./Ticket1.java:7: incompatible types
    found : java.lang.Object
    required: java.lang.Integer
    return price;

    the program is below

    the abstract class


    public abstract class Ticket <AnyType>{

    public AnyType price;
    public Ticket(AnyType p){
    price =p;}
    public abstract AnyType read();

    }

    _____________________________________________

    the subclass

    public class Ticket1 extends Ticket{
    private static final Integer free= 0;
    public Ticket1(){
    super(free);
    }
    public Integer read(){
    return price;
    }


    }

    ______________________________________________

    main to use classes

    class TestTicket {

    public static void main (String args[])
    {
    Ticket<Integer>a = new Ticket1();
    Integer value = a.read();
    System.out.println(value);

    }

    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Doesn't Ticket1 need to extend Ticket<Integer>?

    Java Code:
    class Ticket1 extends Ticket<Integer> {
       private static final Integer free = 0;
    
       public Ticket1() {
          super(free);
       }
    
       public Integer read() {
          return price;
       }
    
    }

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Your code doesn't even compile; check the error diagnostics, they tell you what's wrong. Your class Ticket1 is either a generic class itself or it extends a concrete implementation of a generic Ticket class.

    kind regards,

    Jos

    edit: hrmph, too slow again ...
    Last edited by JosAH; 07-24-2010 at 02:57 PM.

  4. #4
    bflhr673 is offline Member
    Join Date
    Jul 2010
    Posts
    4
    Rep Power
    0

Similar Threads

  1. incompatible types error
    By magic in forum New To Java
    Replies: 3
    Last Post: 06-02-2010, 04:58 PM
  2. Incompatible operand types int and double[][]
    By Haske2r in forum New To Java
    Replies: 2
    Last Post: 01-21-2010, 05:26 PM
  3. Incompatible types
    By coltragon in forum New To Java
    Replies: 5
    Last Post: 01-15-2010, 04:47 PM
  4. Replies: 3
    Last Post: 12-14-2008, 01:52 PM
  5. Replies: 6
    Last Post: 10-08-2008, 08:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •