Bug 124864 - Problems with nested generics
Problems with nested generics
Product: java
Classification: Unclassified
Component: Compiler
All All
: P4 with 3 votes (vote)
: 6.x
Assigned To: Dusan Balek
Depends on:
  Show dependency treegraph
Reported: 2008-01-08 07:16 UTC by nicolo
Modified: 2016-07-07 07:18 UTC (History)
0 users

See Also:
Issue Type: DEFECT


Note You need to log in before you can comment on or make changes to this bug.
Description nicolo 2008-01-08 07:16:33 UTC
if I have a class Class1<B> and another class Class2<B, V, C>, and a class Class3 with a method
 public boolean meth(final Class2<? extends B, ?, ? extends Class1<? extends B>>); when I call the method meth from an
other class the editor shows me an error message: "incompatible types: found Class3.meth, required boolean"
The compiler works, but the editor shows me the error
Comment 1 Jan Lahoda 2008-01-15 06:30:33 UTC
Could you please try to find a small reproducible test case and attach it to this issue? Thanks.
Comment 2 nicolo 2008-01-15 08:09:51 UTC
File Base.java
public class Base {

File Model.java
public class Model<B extends Base> {

File Contribution.java
public abstract class Contribution <B extends Base, V, C extends Model<?>> extends Model<B> {

	public Contribution(){

File Manager.java
public class Manager {

	public boolean createContribution(final Contribution<? extends Base, ?, ? extends Model<? extends Base>> contribution) {
		return false;

File Main.java
public class Main {

	public static void main (String[] args){
		final Contribution <?, ?, ?> contr = new Contribution () {};
		Manager man = new Manager();
		if (man.createContribution(contr)){ //It shows the error here!!!!!!!!!!!!!!!!!

It shows an error: Incompatible types: required boolean, found createContribution.
But it compiles and run
Comment 3 matthies 2009-10-30 19:38:23 UTC
Still reproducable with build 200910261401, although with a different error message. But external javac from JDK 1.6 
also gives an error.

There is a simple workaround though, just declare createContribution as:

    public boolean createContribution(final Contribution<?, ?, ?> contribution)

It can be taken as a general coding rule that one shouldn't repeat type parameter bounds in wildcard arguments. For 
example it's redundant to write Model<? extends Base>, as the "extends Base" is already implicit in "Model<?>", because 
Model is defined as "Model<B extends Base>". Likewise, it's redundant to write "Contribution<? extends Base, ?, ? 
extends Model<? extends Base>>", because all these bounds are already implicit in "Contribution<?, ?, ?>".

Of course javac should still be fixed to correctly recognize those equivalencies.
Comment 4 Martin Balin 2016-07-07 07:18:38 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

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo