phamow / fest

Automatically exported from code.google.com/p/fest
0 stars 0 forks source link

Generic extension of GenericTypeMatcher doesn't work as expected #257

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I have a type matcher which extends GenericTypeMatcher:

public class ExtendedGenericTypeMatcher<T extends Component>
    extends GenericTypeMatcher<T>

It implements isMatching(T component) as follows:

@Override
protected boolean isMatching(final T component)
{
    return true;
}

So, my matcher should match all components of type T.

The problem is that it matches all java.awt.Component s.

It seems to me that it's a Java generics issue (but it isn't a Java bug).
I've posted a question on the Java forum to clarify:
http://forums.sun.com/thread.jspa?threadID=5354195

I'm thinking of changing the signature of GenericTypeMatcher#matches to
accept a T instead of a Component. This way the compiler would force a cast
to a concrete type, when calling the method. Casting to a concrete type
would work as expected.
This change would have a massive effect on the library users, because
ComponentMatcher would have to be made generic.

Thanks,
Csabi

P.S.: Attached is a small program which demonstrates the problem.

Original issue reported on code.google.com by csaba.ju...@gmail.com on 10 Dec 2008 at 9:35

Attachments:

GoogleCodeExporter commented 9 years ago
Many thanks Csabi!

Original comment by Alex.Rui...@gmail.com on 10 Dec 2008 at 1:22

GoogleCodeExporter commented 9 years ago
Hi Csabi,

I fixed the bug. The solution was to have the constructors in
org.fest.swing.core.GenericTypeMatcher take the supported type as parameter to
guarantee correct casting in the 'isMatching' method.

You can review the changes at 
http://code.google.com/p/fest/source/detail?r=2070 (r2070)

Many thanks for your help!!! :)

-Alex

Original comment by Alex.Rui...@gmail.com on 19 Dec 2008 at 5:17

GoogleCodeExporter commented 9 years ago
Thank you for fixing it Alex, best regards,
Csabi

Original comment by csaba.ju...@gmail.com on 14 Jan 2009 at 5:03

GoogleCodeExporter commented 9 years ago
Csabi, thank you for finding the bug! :)

Cheers,
-Alex

Original comment by Alex.Rui...@gmail.com on 14 Jan 2009 at 5:13