Bug 92873 - [quick fix] replace <? super T> with <? extends T>
Summary: [quick fix] replace <? super T> with <? extends T>
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-27 02:22 EDT by R Lenard CLA
Modified: 2009-01-23 11:32 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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);
    }
}