I am generating Classes from XSD. For each revision in XSD, A new class is generated with same name but under a different package. If "Foo"is the class, the class name will be : model.v1.Foo , model.v2.Foo etc. fro each revision.
Irrespective of the version of class, some operations are common. Is there any way to create a common method, that can take up any version of Foo class
public static String doOperation(Foo foo){
//Do some operation
}
The DoOperation method needs to be common for all the versions.
One possibility is create an interface like:
public interface FooIF {
public default String doOperation(Foo foo){
System.out.println("doOperation executed");
return null;
}
}
And have Foo
implement it:
public class Foo implements FooIF{
public Foo() {
}
public static void main( String[] args) {
Foo f = new Foo();
f.doOperation(null);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.