Bug 72998 - [1.5] Internally, generic types should be unique.
Summary: [1.5] Internally, generic types should be unique.
Status: RESOLVED DUPLICATE of bug 77052
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.1 M3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-31 14:28 EDT by Marco Qualizza CLA
Modified: 2004-10-27 07:04 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marco Qualizza CLA 2004-08-31 14:28:29 EDT
Given the two following classes:
-----
package test;

import java.util.Iterator;

public class Tree<E> {
   private TreeNode<E> root;

   public void doSomething() {
      for (TreeNode<E> child : root.children()) {
         // root.children() should work??
      }
   }

   public void doSomethingElse() {
      for (Iterator<TreeNode<E>> it = root.children().iterator(); it.hasNext();) {
         // this also should work
      }
   }
}
-----
package test;

import java.util.Set;

public class TreeNode<E> {
   private Set<TreeNode<E>> children;
   
   public Set<TreeNode<E>> children() {
      return children;
   }
}
-----

1. The "for (TreeNode<E>..." line in Tree#doSomething() should be valid. 
Instead, it generates "Type mismatch: cannot convert from element type
test.TreeNode<E> to test.TreeNode<E>".

2. The "for (Iterator..." line in Tree#doSomethingElse() should also be good,
but it generates "Type mismatch: cannot convert from Iterator<TreeNode<E>> to
Iterator<TreeNode<E>>"

If either loop is replaced with:
      for (Iterator it = root.children().iterator(); it.hasNext();) {
         TreeNode<E> child = (TreeNode<E>)it.next();
         // ...
      }

then everything is fine (minus the warning generated by the cast).

FURTHERMORE.  (Yes, there's even more! :-) )
The errors in 1. and 2. do *not* display on the Problems view unless a
Project->Clean is performed, and then they disappear the first time that the
class is re-saved.
Comment 1 Philipe Mulet CLA 2004-10-27 07:04:12 EDT
Same issue as in bug 77052 which has simpler testcase.
Still added regression test: GenericTypeTest#test324 for this very scenario.

*** This bug has been marked as a duplicate of 77052 ***