C
Christopher Benson-Manica
Recently, it chanced that some code like this was written:
public class Bar extends Foo {
// Foo has one constructor, taking a List<String> as an argument
public Bar(final Object... args) {
super( new Callable<List<String>> () {
public List<String> call() {
final List<String> list = new LinkedList<String>();
// Transform args into String's and put them in the list
return list;
}
}.call() );
}
}
The motivation is to transform Foo's constructor interface into
something that is more convenient for Bar's clients. This strikes me
as grievously hacky, but I also don't see another way to accomplish
this aside from refactoring, which may not even be possible depending
on where Foo comes from. Is this a reasonable (or at least accepted)
idiom for accomplishing this goal, or is there a more elegant
solution?
public class Bar extends Foo {
// Foo has one constructor, taking a List<String> as an argument
public Bar(final Object... args) {
super( new Callable<List<String>> () {
public List<String> call() {
final List<String> list = new LinkedList<String>();
// Transform args into String's and put them in the list
return list;
}
}.call() );
}
}
The motivation is to transform Foo's constructor interface into
something that is more convenient for Bar's clients. This strikes me
as grievously hacky, but I also don't see another way to accomplish
this aside from refactoring, which may not even be possible depending
on where Foo comes from. Is this a reasonable (or at least accepted)
idiom for accomplishing this goal, or is there a more elegant
solution?