Thanks for your testcase. Imagine, you use the DummyCalendar in Calendar2DateFieldConversion.
javaToSql will be ok. (... if (source instanceof Calendar) ...)
but sqlToJava will materialize not the DummyCalendar (that you need), but a GregorianCalendar.
(... GregorianCalendar cal = new GregorianCalendar()...)
public class TestThingy2 extends TestCase
{
public void testCalendarConv()
{
DummyCalendar dc0 = new DummyCalendar();
Date d = Calendar2DateFieldConversion.javaToSql(dc);
Calendar dc1 = Calendar2DateFieldConversion.javaToSql(d);assertEquals(dc1, dc0); //will fail
DummyCalendar dc2 = (DummyCalendar)dc1; //will fail } }
David
Just for curiosity what is the purpose of you own calendar class ?
from Calendar apidoc:
Subclasses of Calendar interpret a Date according to the rules of a specific calendar system. The platform provides one concrete subclass of Calendar: GregorianCalendar. Future subclasses could represent the various types of lunar calendars in use in many parts of the world.
..so there are more calendars planned in JDK and also there is no guarantee, that there are no other custom subclasses yet.
I think it's a general rule, to take into accout subclasses, everywhere applicable (~ not final classes), esp. in tools, libraries, frameworks...
Indeed it is - and instanceof covers this. I've just knocked together (and appended) a test case to illustrate and prove this : both java.util.Calendar and my DummyCalendar are *both* instances of Calendar. This also holds true of interfaces : if a class A implements interface B, an instance of of class A is an instance of class B. Moreover, is class C extends class A, an instance of class C is also an instance of class B. Hopefully the test case is clearer and more lucid than this explanation :
Cheers,
Charles.
public class TestThingy extends TestCase { public void testInstanceOf() { assertTrue(new GregorianCalendar() instanceof java.util.Calendar); assertTrue(new DummyCalendar() instanceof java.util.Calendar); assertTrue(new AnObject() instanceof AnInterface); assertTrue(new ASubclass() instanceof AnInterface); }
public class DummyCalendar extends Calendar { public void add(int field, int amount) { }
protected void computeFields() { }
protected void computeTime() { }
public int getGreatestMinimum(int field) { return 0; }
public int getLeastMaximum(int field) { return 0; }
public int getMaximum(int field) { return 0; }
public int getMinimum(int field) { return 0; }
public void roll(int field, boolean up) { } }
public interface AnInterface {} public class AnObject implements AnInterface {} public class ASubclass extends AnObject {}
}
___________________________________________________________
HPD Software Ltd. - Helping Business Finance Business
Email terms and conditions: www.hpdsoftware.com/disclaimer
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
