[jsword-devel] Java conundrum
DM Smith
dmsmith at crosswire.org
Tue May 7 06:12:29 MST 2013
Sorry for not replying earlier. Have been on holiday.
This conundrum should bee seen as a bug. Both should return the same value.
I have an idea of what is happening (I have a masters degree in computer science for compiler construction), but until I trace it I won't be sure. I think that it is compile time determination of what is being called.
In the gen_all case, it is known that it is a VerseRange and that VerseRange has a more specific contains(Verse). So that is called.
In the gen_allKey case, it is no longer a VerseRange but a Key (which should not know anything about a Verse, since it is supposed to work for all kinds of Keys). So it cannot call contains(Verse) but only contains(Key).
I'll see what I can find out.
-- DM
On May 4, 2013, at 5:34 AM, Martin Denham <mjdenham at gmail.com> wrote:
> Here is an interesting problem (based on VerseRangeTest.java):
>
> private VerseRange gen_all = ...;
>
> public void testKeyContainsVerse() {
> // this passes
> assertTrue(gen_all.contains(gen11));
>
> // this fails
> Key gen_allKey = gen_all;
> assertTrue(gen_allKey.contains(gen11));
> }
>
> This caught me out for a while. I think the second assert should pass but Key is an interface with a single non-overloaded contains():
> boolean contains(Key key);
>
> Whereas VerseRange contains overloaded methods like contains(Verse) that are not called because the Key interface is being used. At least that is what I think is happening.
>
> Is this a bug?
>
> Martin
>
>
>
>
> _______________________________________________
> jsword-devel mailing list
> jsword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/jsword-devel
More information about the jsword-devel
mailing list