Results 1 to 4 of 4
- 07-24-2010, 02:46 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 4
- Rep Power
- 0
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);
}
}
-
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; } }
- 07-24-2010, 02:54 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
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.
- 07-24-2010, 03:10 PM #4
Member
- Join Date
- Jul 2010
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
incompatible types error
By magic in forum New To JavaReplies: 3Last Post: 06-02-2010, 04:58 PM -
Incompatible operand types int and double[][]
By Haske2r in forum New To JavaReplies: 2Last Post: 01-21-2010, 05:26 PM -
Incompatible types
By coltragon in forum New To JavaReplies: 5Last Post: 01-15-2010, 04:47 PM -
Incompatible types??? Counting through an array of Strings
By ookie833 in forum New To JavaReplies: 3Last Post: 12-14-2008, 01:52 PM -
Error: incompatible types, found: int required: boolean
By silvia in forum New To JavaReplies: 6Last Post: 10-08-2008, 08:09 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks