Tuesday, 15 February 2011

infer generics with inteface - java -



infer generics with inteface - java -

i have next inteface:

public interface evaluator<t> { t evaluate(collection<extractable> sample); }

and class implementing inteface:

public class precisionevaluator implements evaluator<map<triple<short, integer, string>, attributeprecisionbean>> { @override public map<triple<short, integer, string>, attributeprecisionbean> evaluate(collection<extractable> sample){ ...

}

so usage of above be:

evaluator<map<triple<short, integer, string>, attributeprecisionbean>> eval = new precisionevaluator();

is there way to create interface evaluator implicitly homecoming generic type defined in class implementing it? usage be:

evaluator eval = new precisionevaluator();

or there cleaner way go it?

yeah there way : larn scala, syntax far simpler java's, to, among other reasons, compiler type inference.

more seriously, cannot improve java, if utilize evaluator lone going compiled evaluator<object>, not allow have type safety , polymorphism. here creating class class customtriple extends triple<short,integer,string>> have shorter.

java generics

No comments:

Post a Comment