Description of the problem: I want to be able to use an ArrayList from functions passed from another class (where the functions are defined in this other class). If the list of functions that can have different types of input and return are defined in one class, I want to be able to pass an ArrayList from some of them with possible duplicates as a parameter to some other constructor or method of the class and perform operations using them.
Description of the code: The code below is a very simplified example that does not make much sense from a design point of view. The focus of the problem lies in the getResult() method inside SomeClass and generally how to use the ArrayList from functions after they appear.
Trying to solve a problem: Implementing the getResult () method is an example of one of many attempts to use a list of functions. Again, please ignore the code design. This was done in such a way as to try to make an example of the problem as short as possible.
Simple tester class
package com.Testing; import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.function.Function; public class Tester { public static void main(String[] args) {
Another class
package com.Testing; import java.util.List; import java.util.function.Function; public class SomeClass { List<Function> operations; double initialValue; public SomeClass(List<Function> newOperations, double newInitialValue){ operations = newOperations; initialValue = newInitialValue; } public double getResult(){ double result = 0.0;
java function arraylist java-8
John May 16 '15 at 9:45 a.m. 2015-05-16 09:45
source share