I'm getting this compiler error in netbeans:
incompatible types required: String found: java.lang.String
I'm kind of lost as why this happens?
Code:
private class StringIterator<String> implements Iterator<String> {
private Iterator<Entry<K, byte[]>> i = internalMap.entrySet().iterator();
@Override
public boolean hasNext() {
return i.hasNext();
}
@Override
public String next() {
return decompress(i.next().getValue());// error on this line
}
@Override
public void remove() {
i.remove();
}
}
You should remove the type argument from the StringIterator class. This is causing the compiler to consider any occurrence of String in the class to be a generic type rather than java.lang.String.
private class StringIterator implements Iterator<String> {
What is decompress? If it is a method, then it must also return String.
What are your imports? Did you maybe import the "wrong" String
? Plus, what is decompress
?
Update: see other reply, which has the correct answer. You named your generic "String". Remove the generic you don't use.
I wanted to supply another situation where this can occur as it was stumping me for a while. The solution gkamal stated is correct.
In my case, I had the following:
public class NodeLabelTransformer<V, String> implements Transformer<V, String>
{
....
}
but I was receiving the error.
@Override
public String transform(V s)
{
StringBuilder label;
label = new StringBuilder();
label.append("MyLabelText");
return (label.toString());
}
In this case the solution is that my class should be declared as:
public class NodeLabelTransformer<V> implements Transformer<V, String>
{
I just wanted to point out, that the parameters of the Transformer interface are still the same, but my class declaration differs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With