Im new to Java and I completely stuck on it. I have to implement "summator" class, to summ all Numbers in it. For example this class holds a number
public class NumericNode <N extends Number>{
private N nodeValue = null;
public NumericNode(N initValue){
this.nodeValue = initValue;
}
public N getNodeValue() {
return nodeValue;
}
}
second class need to do some summ
public class NumericSummatorNode<NumericNode, T> {
private T nodeValue;
private NumericNode[] inlets;
public NumericSummatorNode(NumericNode...inlets) {
this.summ(inlets);
}//constructor
public void summ(NumericNode... summValues) {
ArrayList<NumericNode> numericList = new ArrayList<>();
int count = summValues.length;
for (int i = 0; i < count; i++){
numericList.add(summValues[i]);
}
for (int j = 0; j < count; j++){
Method method = numericList.get(j).getClass().getMethod("getNodeValue", null);
method.invoke(numericList.get(j), null);
}
}
And here is the main:
public static void main(String[] args){
NumericNode n1 = new NumericNode(5);
NumericNode n2 = new NumericNode(4.3f);
NumericNode n3 = new NumericNode(24.75d);
NumericNode n5 = new NumericNode((byte)37);
NumericNode n6 = new NumericNode((long)4674);
NumericSummatorNode s1 = new NumericSummatorNode(5, 4.6f, (double)4567);
NumericSummatorNode s2 = new NumericSummatorNode(n1, n2);
NumericSummatorNode s3 = new NumericSummatorNode();
s2.summ(n1, n2);
}//main
So I have an issue to call getNodeValue() method from an NumericNode object in my array list. How do I make this work?