I'm a bit lost with this. I have code (that I didn't write) which has a class called BitSetExt, which extends BitSet. The signature looks like:
private class BitSetExt extends BitSet implements Set<Integer>
The stream() method is not overridden in the extended class. I do know that the code compiles just fine with Java 1.6. In Eclipse with Java8, I get the error:
The return types are incompatible for the inherited methods Collection.stream(), BitSet.stream().
If I attempt to override stream() and change the IntStream return type to anything, I get a different error and a suggestion to change the return type to IntStream (which apparently isn't compatible). So, what am I not understanding and how can I fix this code?
Thanks for any help.
Since Java 8, BitSet has a method declared as
and
Set<Integer>
has a method with the same name, declared asSince those methods have the same name but an incompatible return type, it's impossible to extend BitSet and implement Set at the same time.
You'll have to refactor the class so that it doesn't implement
Set<Integer>
anymore and, for example, add a method which returns a view over the object, implementingSet<Integer>
:That class will never compile in Java 8.
Set<Integer>
requires that you implement a method with the signaturewhile
BitSet
provides an implementation with the signatureAnd an
IntStream
is not a subtype ofStream<integer>
. There is no type that will satisfy both requirements.