Re: instruction java
atef wrote:
constructor = learnerClass.getConstructor(new Class[]
{NumericEntries.class, boolean.class});
if (!(entries instanceof NumericEntries)) {
System.out.println("[ Error : entries are instance of"+
> entries.getClass()+" and contain " +
entries.getNbAttribute(Attribute.SYMBOLIC) +
> " symbolical attributes ]");
throw new NumericEntriesException();
}
parameters = new Object[] {new
SubNumericEntries((NumericEntries)entries),
> new Boolean(regression)};
SingleSupervisedLearner learner =
(SingleSupervisedLearner)constructor.newInstanc(parameters);
return learner;
[ code modified and truncated somewhat ]
bon je veus comprendre les lignes marqu9s et surtout ces 3 l0:
(Translated)
I want to understand the marked lines especially these three:
[snipped]
These lines are using Java reflection: dynamically getting the
constructor from a class and then calling it, obviously not using the
new variable-argument features from Java 5. Since the code appears to
come from a neural network library; I am guessing that the learnerClass
is an argument passed to the class at an earlier point in time for use
in the dynamic generation presented here.
Supposing that learningClass were the class object for, say,
DefaultLearner, the code would act in effect like the following line:
return new DefaultLearner((NumericEntries)entries, regression);
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth