Bug 78027 - [1.5][compiler] Generics, bound mismatch
Summary: [1.5][compiler] Generics, bound mismatch
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M4   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-06 21:10 EST by Heri CLA
Modified: 2006-01-09 05:01 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 Heri CLA 2004-11-06 21:10:16 EST
Build 200411050810

The following code can be compiled with javac, but the line
  return m_manager.getById(getClass(), new Integer(1));
produces this compile error in Eclipse:
  Bound mismatch: The generic method getById(Class<T>, Integer) 
  of type Test<C>.Manager<C> is not applicable for the arguments 
  (Class<? extends Test<C>>, Integer) since the type ? extends Test<C> 
  is not a valid substitute for the bounded parameter <T extends ITest<C>>

public class TestCtx 
{
}

public interface ITest<C extends TestCtx>
{ 
}

abstract public class Test<C extends TestCtx> implements ITest<C>
{
  protected Manager<C> m_manager;
  
  public ITest<C> get()
  {
    return m_manager.getById(getClass(), new Integer(1));
  }
    
  public static class Manager<C extends TestCtx>
  {
    public <T extends ITest<C>> T getById(Class<T> cls, Integer id)
    {
      return null;
    }
  }
}
Comment 1 Philipe Mulet CLA 2004-11-08 17:26:53 EST
Generic method should also substitute according to their declaring class (if
parameterized type).
Added regression test: GenericTypeTest#test394.
Fixed
Comment 2 Olivier Thomann CLA 2004-12-14 15:46:07 EST
Compile without an error now.
Verified in 200412140800
Comment 3 Liu yehui CLA 2006-01-07 03:58:17 EST
Eclipse 3.1 report bound mismatch on Enum_.java in Retrotranslator(http://retrotranslator.sourceforge.net/), but it can be compiled by SUN JDK.

Following is a simplified version to reproduce the bug.

public abstract class BoundMismatch<C extends BoundMismatch<C>> {
	public static <T extends BoundMismatch<T>> T getDefault(Class<T> clz){
		return null;
	}
	
	public Object getDefault(){
		return getDefault(getClass());
	}
}
Comment 4 Philipe Mulet CLA 2006-01-09 03:32:29 EST
The present bug report describes another issue than the last added comment. If you still want it to be considered, then please open a separate bug for it.
Comment 5 Philipe Mulet CLA 2006-01-09 05:01:10 EST
Entered bug 123078 since I investigated a fix in the meantime.