| Summary: | Generic methods accepting different types! | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Prashant Deva <prashant.deva> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED INVALID | QA Contact: | |
| Severity: | critical | ||
| Priority: | P3 | ||
| Version: | 3.1 | ||
| Target Milestone: | 3.1 M7 | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | |||
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 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?? Oops, sorry i get it now. My understanding of generics was screwed up ;) |
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