Android : Java: how to specific "forEach" action type

on Sunday, October 26, 2014


This is my test code, i use intellij idea:



package ro.ex;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.function.Consumer;

class Ex {
static class MyArrayList<E> extends ArrayList {
public MyArrayList(Collection c) {
super(c);
}

@Override
public void forEach(Consumer action) {
super.forEach(action);
}
}

public static void main(String[] args) throws IOException {
MyArrayList<String> a = new MyArrayList<String>(Arrays.asList("arg", "arg2"));
for (String e : a) {

}
}

}


and idea raise "Error:(23, 25) java: incompatible types: java.lang.Object cannot be converted to java.lang.String"


i also try ArrayList



public static void main(String[] args) throws IOException {
ArrayList<String> a = new ArrayList<String>(Arrays.asList("arg", "arg2"));
for (String e : a) {

}
}


everything work well.


my question is:


How to make former code pass idea syntax checker?


0 comments:

Post a Comment