Bug 98478 - Bounds mismatch error: compiler problem
Summary: Bounds mismatch error: compiler problem
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.1 RC2   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-06 05:21 EDT by oliver CLA
Modified: 2005-06-06 05:57 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 oliver CLA 2005-06-06 05:21:30 EDT
System: 
=======

Win2000, Eclipse 3.1M6

Test code:
==========

import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;

public class Test {
    
    public interface Base {
    }
    
    abstract class Action<T extends Base> {
    }

    public class ActionImpl<T extends Base> extends Action<T> implements
Comparable<ActionImpl> {
        public int compareTo(ActionImpl o) {
            return 0;
        }
    }

    public void test() {
        Set<ActionImpl> set = new TreeSet<ActionImpl>();
        Collections.max(set);
    }
}

Javac compiles this code without warning but the Eclipse compiler produces the
following error:

"Bound mismatch: The generic method max(Collection<? extends T>) of type
Collections is not applicable for the arguments (Collection<? extends
Test.ActionImpl>) since the type Test.ActionImpl is not a valid substitute for
the bounded parameter <T extends Object & Comparable<? super T>>"

A workaround for the problem is to declare the variable as:

        Set<ActionImpl<Base>> set = new TreeSet<ActionImpl<Base>>();

However given that it compiles with javac I have submitted this as a bug.
Comment 1 Philipe Mulet CLA 2005-06-06 05:55:46 EDT
Added GenericTypeTest#test718.

Works fine in latest. M6 is old, since then M7 and RC1 got issued.
Comment 2 Philipe Mulet CLA 2005-06-06 05:57:22 EDT
Also note that both compilers are warning about:

1. WARNING in Test.java
 (at line 21)
	Collections.max(set);
	^^^^^^^^^^^^^^^^^^^^
Type safety: Unchecked invocation max(Collection<? extends X.ActionImpl>) of the
generic method max(Collection<? extends T>) of type Collections