given a class like
class MyDate extends java.util.Date {
//add some functionality
}
you create your own Date Object which inherits all functionality.
But if you try to use this functionality like this
MyDate d = MyDate.parse('yyyy','2013')
you will run into the problem that the parse method will return a java.util.Date which can’t be casted to your MyDate.
You can write your own cast through the asType() functionality, but this will not help, because you would have to add it to the Date() class (I know that’s possible, but I would like to avoid it).
Is there another way to solve this Problem?
Groovy’s
Date.parsemethod will return a Date object. If you want it to return yourMyDateobject, you have to write it (overriding, but still using the super):You will also need to inherit the constructors (through this groovy transform) or write your own constructor.