You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@reef.apache.org by Tobin Baker <td...@cs.washington.edu> on 2015/10/15 02:06:10 UTC
cannot specify empty string as default value for OptionalParameter
variables
Hi, I've noticed that if I have an OptionalParameter<String> in a
ConfigurationModule and annotate the associated class with a default value
of "", I get an "infeasible injection plan" error if I leave the variable
unset. It looks like Tang considers any injected constructor param
annotated with this class to be null, and refuses to inject it. So I'm
apparently forced to specify a dummy non-empty placeholder default value
for all OptionalParameter<String> variables in my configuration module and
check for that in my code instead of null or the empty string. Example:
public final class MyConfigurationModule extends ConfigurationModuleBuilder
{
public static final OptionalParameter<String> TEST = new
OptionalParameter<>();
public static final ConfigurationModule CONF = new MyConfigurationModule()
.bindNamedParameter(Test.class, TEST)
.build();
@NamedParameter(default_value = "")
public class Test implements Name<String> {
}
}
public class TestInjection {
@Inject
public TestInjection(@Parameter(MyConfigurationModule.Test.class) final
String testString) {
System.out.println(testString);
}
}
public static void main(String[] args) {
Tang t = Tang.Factory.getTang();
Configuration c = MyConfigurationModule.CONF.build();
Injector i = t.newInjector(c);
TestInjection test = i.getInstance(TestInjection.class)
}