Incompatible types when accessing Map # entrySet ()

I am working on a simple reader of configuration files for fun, but I get an odd error when writing a test method. It has a loop in it for, and I made sure that this is causing the problem. This gives me this compilation error:

Incompatible types:
    Required: java.util.Map.Entry
    Found: java.lang.Object

The card declaration is as follows:

Map<String, String> props = new HashMap<String, String>();

The cycle is forwritten as follows:

for (Map.Entry<String, String> entry : props.entrySet()) {
    //Body
}

SSCCE without import, which demonstrates the problem (at least in IntelliJ):

public class A {
    public static void main(String[] args) {
        Map<String, String> props = new HashMap<String, String>();
        for (int i = 0; i < 100; i++) {
            props.put(new BigInteger(130, random).toString(32), new BigInteger(130, random).toString(32));
        }
        for (Map.Entry<String, String> entry : props.entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }
    }
}

map Map<String, String>, . googled , , , , ! - . . , , - .

+4
1

, - .

class ATest<T> {
  Map<String, String> props = new HashMap<String, String>();

  void aTest() {
    // Works fine.
    for (Map.Entry<String, String> entry : props.entrySet()) {
    }
  }

  void bTest() {
    ATest aTest = new ATest();
    // ERROR! incompatible types: Object cannot be converted to Entry<String,String>
    for (Map.Entry<String, String> entry : aTest.props.entrySet()) {
    }
  }

  void cTest(Map props) {
    // ERROR! incompatible types: Object cannot be converted to Entry<String,String>
    for (Map.Entry<String, String> entry : props.entrySet()) {
    }
  }

}

, bTest ATest . Java , , , <String,String> props .

- - cTest.

+3

All Articles