aspose file tools*
The moose likes Java in General and the fly likes Bizarre Incompatible Types Complaint Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Bizarre Incompatible Types Complaint" Watch "Bizarre Incompatible Types Complaint" New topic
Author

Bizarre Incompatible Types Complaint

Kevin Simonson
Ranch Hand

Joined: Oct 22, 2011
Posts: 113
I've got an application that currently uses an {ArrayList} to build up a list of a lot of elements when I don't know ahead of time how large the list is going to be. But due to the way I'm doing it, it would be nice if I could eliminate a (potentially high) number of elements whose indices are above a given value, without having to call {remove()} on each and every one of those elements.

So I wrote a class {Derived} that extends {ArrayList} and therefore inherits all of {ArrayList}'s methods, while overriding {iterator()} and {add()}, and adding {reset()} that allows you to get rid of those pesky high index elements in constant time. To do a more thorough job I probably should have overridden the other {add()} method, and maybe others, but I thought this program should be enough for proof of concept.

The actual program is:

But when I try to compile this I get the bizarre error message:

Derived.java:25: incompatible types
found : El
required: El
return get( position++);
^
1 error

How in the world can type {El} be incompatible with itself? I don't understand this at all. Can anyone explain what this compiler message actually means? Is this an indication that my compiler might be buggy?

Kevin S
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

At line 5 you declare a type variable named "El". Then at line 9 you declare another type variable, also named "El". Apparently (judging from the error message) those two declarations declare two different type variables which just happen to have the same name.

I'm guessing here, but try



and change line 41 to match that change. Here you aren't declaring a new type variable any more, you are using the existing variable which was declared by the outer class. Give that a try and see if I'm right.
Kevin Simonson
Ranch Hand

Joined: Oct 22, 2011
Posts: 113
Paul Clapham wrote:At line 5 you declare a type variable named "El". Then at line 9 you declare another type variable, also named "El". Apparently (judging from the error message) those two declarations declare two different type variables which just happen to have the same name.

I'm guessing here, but try



and change line 41 to match that change. Here you aren't declaring a new type variable any more, you are using the existing variable which was declared by the outer class. Give that a try and see if I'm right.

Thanks, Paul; that did the trick; my code is working now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bizarre Incompatible Types Complaint