This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 244603 - Generic type arguments applied wrongly for hint "Create class"
Summary: Generic type arguments applied wrongly for hint "Create class"
Status: REOPENED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0.1
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-20 15:32 UTC by Jachym_Vojtek
Modified: 2016-07-11 07:03 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jachym_Vojtek 2014-05-20 15:32:59 UTC
See couple of examples for hint "Create class" which tries to solve unresolved name.

1) Superclass not taken into account
import java.util.ArrayList;

public class Test<T> {

    ArrayList<? extends Number> l = new MyList<Number>();

}

Actual result:
class MyList<T> {

    public MyList() {
    }
    
}

Result I would expect:
import java.util.ArrayList;

class MyList<T> extends ArrayList<T> {

    public MyList() {
    }
    
}


2) Superinterface taken into account but wildcard is used as a type argument for a generic supertype which is not possible.

import java.util.List;

public class Test<T> {

    List<? extends Number> l = new MyList<Number>();    

}

Actual result:
import java.util.List;

class MyList implements List<? extends Number> {

    public MyList() {
    }
    
}

Result I would expect:
import java.util.List;

class MyList<T> implements List<T> {

    public MyList() {
    }
    
}

3) Superclass taken into account but wildcard is used as a type argument for a generic supertype which is not possible.

import java.util.ArrayList;

public class Test<T> {

    ArrayList<? extends Number> l = new MyList();    

}

Actual result:
import java.util.ArrayList;

class MyList extends ArrayList<? extends Number> {

    public MyList() {
    }
    
}

Result I would expect:
import java.util.ArrayList;

class MyList extends ArrayList<Number> {

    public MyList() {
    }
    
}

4) Superinterface taken into account but wildcard is used as a type argument for a generic supertype which is not possible.

import java.util.List;

public class Test<T> {

    List<? extends Number> l = new MyList();

}

Actual result:
import java.util.List;

class MyList implements List<? extends Number> {

    public MyList() {
    }
    
}

Result I would expect:
import java.util.List;

class MyList implements List<Number> {

    public MyList() {
    }
    
}
Comment 1 Jachym_Vojtek 2014-05-20 15:51:18 UTC
One additional curious example:
5)
import java.util.HashMap;

public class Test<T> {

    HashMap<?, ?> m = new MyMap();

}

Actual result:
import java.util.HashMap;

class MyMap extends HashMap<?, ?> {

    public MyMap() {
    }
    
}

Result I would expect:
Hmm, hard to say.
Comment 2 Jachym_Vojtek 2014-05-21 11:04:53 UTC
6) Unsolvable example:
public class Test2<T extends Number> {

    T myNumber = new MyNumber();

}

Actual result:
class MyNumber {

    public MyNumber() {
    }
    
}

Result I would expect:
I do not see any valid solution for this case.
Comment 3 Martin Balin 2016-07-07 07:18:07 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss
Comment 4 Jachym_Vojtek 2016-07-11 07:03:49 UTC
Checked in NetBeans IDE Dev (Build 201607110002).
Still needs to be fixed.