dimanche 4 janvier 2015

Parse custom Objects with string input

I want to parse objects where I have an input value. The object has subclasses.


I don't want to create an instance when I want to parse the string. But I want to override the method 'parse'.



class A {
public A(object param) {
//code
}
public A parse(String input) {
//code
}
}

class B extends A {
public B parse(String input) {
//code
}
}


And when I parse the objects I want do it with reflection:



A newObject = Class.forName(className).getMethod("parse", myParseText);


Is there a nice way to do that.






Aucun commentaire:

Enregistrer un commentaire