Bug 95289 - Generic methods accepting different types!
Summary: Generic methods accepting different types!
Status: CLOSED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: 3.1 M7   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-15 00:00 EDT by Prashant Deva CLA
Modified: 2005-05-16 08:56 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Prashant Deva CLA 2005-05-15 00:00:30 EDT
I am using eclipse 3.1m7, this problem also existed in M6.

I have the following method in my class -
private static<T> int indexOf(final T[] array,final T elem)
{
   ...
}
I have these types -

class AContainer
{
   public A[] getAs(){...}
}

class AInfo {
   public A a;
}


I have a method which uses all this like this -

public static void meth(AContainer ac)
{
  ....

  for(AInfo ai: aiArray)
  {
	int index = indexOf(ac.getAs(),ai.a);
  }

}


All is well till here but if i change the above line to -

int index = indexOf(ac.getAs(),ai); //ai.class!=ai.a.class!!!

The above line still compiles, even though the types of both the objects are
different !!!!!

PRASHANT
Comment 1 Philipe Mulet CLA 2005-05-16 07:10:54 EDT
In first case, T got inferred to be of type A; in second case it got inferred to
be of type Object. Note that when hoverring on message sends, the help bubble
shows you what got inferred.

Working as expected; javac agrees with us.
Added GenericTypeTest#test669
Comment 2 Prashant Deva CLA 2005-05-16 08:51:25 EDT
Uhmmm....
I don't really get it, in the method call-
indexOf(ac.getAs(),ai);

Type of First Param = A[]
Type of second Param = AInfo

but our generic method should allow methods of only 1 type, either A or AInfo,
then how is the above method call allowed??
Comment 3 Prashant Deva CLA 2005-05-16 08:56:49 EDT
Oops, sorry i get it now. My understanding of generics was screwed up ;)