title: Java - class cast exception from wrong type
body: <p>Running Java 1.8 (And Spring 4.0, which is responsible for some of this wiring), I have the following code:</p>
  
  <pre><code>public void doStuff(String color, Collection&lt;String&gt; ids)  {
    for (String id : ids) {
  </code></pre>
  
  <p>On that last line, I get the exception:</p>
  
  <pre><code>java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
  </code></pre>
  
  <p>the toString of the collection returns: [521356090]</p>
  
  <p>It is being passed to this method from this code:</p>
  
  <pre><code>doStuff("green", this.regionToIds.get(3L))
  </code></pre>
  
  <p>Why am I getting this exception? Why is the Set and then collection have an object that my foreach loop has a problem with?</p>
  
  <p>This class is wired in as a resource:</p>
  
  <pre><code>private Map&lt;Long, Set&lt;String&gt;&gt; regionToIds;
  
  @Resource(name = Config.REGION_TO_IDS)
  public void setRegionToIds(
      final Map&lt;Long, Set&lt;String&gt;&gt; regionToIds) {
      this.regionToIds = regionToIds;
  }
  </code></pre>
  
  <p>The config file looks like this:</p>
  
  <pre><code>@Bean(name = REGION_TO_IDS)
  public Map&lt;Long, Set&lt;String&gt;&gt; getRegionToIds() { .. }
  </code></pre>
  
  <p>I actually just noticed that I have two beans defined in my Config file, and the value being returned is the value of the other bean, which is a <code>Map&lt;Long, List&lt;Long&gt;&gt;</code>. However, it has an entirely different bean name so I don't understand why that resource is pulling in the wrong bean.</p>