Bug 92873

Summary: [quick fix] replace <? super T> with <? extends T>
Product: [Eclipse Project] JDT Reporter: R Lenard <rlenard>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: ASSIGNED --- QA Contact:
Severity: enhancement    
Priority: P3    
Version: 3.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description R Lenard CLA 2005-04-27 02:22:40 EDT
Often it's easy to get the <? super T> and <? extends T> mixed up.  A useful 
quick fix would suggest the other when the first is obviously wrong but the 
other would probably resolve.
e.g.
% cat Test.java
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author <a href="mailto:foo@bar.com">Foo Bar</a>
 */
public final class Test
{
    /**
     * @param <T>
     * @param from
     * @param clazz to force to T
     * @return as an array
     */
//    public static <T> T[] createFrom(final Collection<? extends T> from, 
final Class<T> clazz) // what I need
    public static <T> T[] createFrom(final Collection<? super T> from, final 
Class<T> clazz) // what I had
    {
        assert from != null;
        assert clazz != null;
        return null;
    }

    /**
     * @param <T>
     * @param from
     * @param val to force to T
     * @return as an array
     */
//    public static <T> T[] createFromVal(final Collection<? extends T> from, 
final T val) // what I need
    public static <T> T[] createFromVal(final Collection<? super T> from, final 
T val) // what I had
    {
        assert from != null;
        assert val != null;
        return null;
    }

    /** Test it. */
    public static void test() {
        final Object type = new Object();
        final List<Double> foo = new ArrayList<Double>();
        final Collection<Double> bar = new ArrayList<Double>();
        
        final Number[] fooed = Test.createFrom(foo, Number.class);
        final Number[] barred = Test.createFrom(bar, Number.class);
        final Object[] gooed = Test.createFrom(bar, Object.class);
        assert barred != null;
        assert fooed != null;
        assert gooed != null;
        
        final Object[] foo2 = Test.createFromVal(foo, type);
    }
}