Ex 1.3

Beiträge: 115
Registriert: 15. Apr 2009 18:08
Wohnort: Ludwigshafen

Ex 1.3

Beitrag von burgi »

Hi everybody,

I am not quite sure how to implement the filter operation within java 7. For sake of completness and to check wether I understood the idea of the filter operation correctly. The idea of the filter method is to receive a predicate, which can be any expression/function, that maps integer values to boolean values, like for example: x => x>5 && x<13 , meaning any int value between 5 and 13 exclusive. For java 7 I don't see how this functionality could be implemented in a closed-form. I do see the opportunity to implement some SAM's to represent some predicates, like isSmaller(x) or isGreater(x), but this solution won't resolve every possible input expression/function.
Maybe someone can give me hint, if I am totally wrong with my ideas or if I missed something important.

Greetings Dominic

Beiträge: 61
Registriert: 21. Okt 2013 21:27

Re: Ex 1.3

Beitrag von imaier »

Updated: sorry, I confused Java 7 with Java 8 in a previous version of this post.

Since you are not asking about it, I assume you know how to implement foreach? If not, have a close look at slide 20 of the exercise slide deck. Even though it is Scala code, note that you can create a class instance, implement an abstract method and pass it to a method (foreach) without storing it in a variable or giving it a name. The same is true in Java. Just try it yourself! I assume everyone knows about Java basics, in particular the material on http://docs.oracle.com/javase/tutorial/ ... asses.html

Filter is not really much different from foreach, except that it does something with the return value of the function argument (the predicate).

It is hard to give your more advice without telling you the solution, so I hope the above helps you.



Zurück zu „Archiv“